Skip to content

Instantly share code, notes, and snippets.

@aberloni
Created May 7, 2015 13:26
Show Gist options
  • Save aberloni/146cfc62f29728da13e8 to your computer and use it in GitHub Desktop.
Save aberloni/146cfc62f29728da13e8 to your computer and use it in GitHub Desktop.
System IO tools
using System.IO;
public class SystemIOTools {
//https://msdn.microsoft.com/en-us/library/vstudio/cc148994%28v=vs.100%29.aspx
static public void copyFolderToFolder(string sourcePath, string targetPath){
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
string fileName = System.IO.Path.GetFileName(s);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
}
static public void emptyFolder(string path){
DirectoryInfo info = new DirectoryInfo(path);
FileInfo[] files;
files = info.GetFiles();
foreach(FileInfo f in files){
f.Delete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment