Thursday 19 September 2013

Copy files exclude one folder

Copy files exclude one folder

Basically I want to copy everything within a folder excluding one folder,
which happens to be where logs are stored for my program. (I know I could
just store logs elsewhere, but I have my reasons). So far I have:
private void btnCopyFiles_Click(object sender, EventArgs e)
{
try
{
//Copy all the files
foreach (string newPath in Directory.GetFiles(@"\\xxx\yyy",
"*.*",
SearchOption.AllDirectories)
.Where(p => p != Logging.fullLoggingPath))
File.Copy(newPath, newPath.Replace(@"\\xxx\yyy", @"C:\bbb"));
using (StreamWriter w = File.AppendText(Logging.fullLoggingPath))
{
Logging.Log("All necessary files copied to C:\\bbb", w);
}
}
catch
{
using (StreamWriter w = File.AppendText(Logging.fullLoggingPath))
{
Logging.Log("Error copying files, make sure you have
permissions to access the drive and write to the folder.",
w);
}
}
}
How can I modify this to exclude one specific folder within \\xxx\yyy

No comments:

Post a Comment