Copying Folder And Files
This code help you to copy all folders, sub folders and files from one location to other.
This code help you to copy all folders, sub folders and files from one location to other.
private static Boolean CopyNewCacheFolder(string SourcePath, string DestinationPath, bool overwriteexisting)
{
Boolean ret = false;
try
{
SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
if (Directory.Exists(SourcePath))
{
if (Directory.Exists(DestinationPath) == false)
Directory.CreateDirectory(DestinationPath);
foreach (string fls in Directory.GetFiles(SourcePath))
{
FileInfo flinfo = new FileInfo(fls);
flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
}
foreach (string drs in Directory.GetDirectories(SourcePath))
{
DirectoryInfo drinfo = new DirectoryInfo(drs);
if (CopyNewCacheFolder(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
ret = false;
}
}
ret = true;
}
catch (Exception ex)
{
ret = false;
}
return ret;
}
Hello
You can also Provide Filter For Directory.GetFiles("Path","Filer");
e.g:
Directory.GetFiles("D:\TestFiles","*.xml");
it will always give XML file form same folder.
Thanks
Umesh