Created
May 7, 2015 13:26
-
-
Save aberloni/146cfc62f29728da13e8 to your computer and use it in GitHub Desktop.
System IO tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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