取自:http: //msdn.microsoft.com/en-us/library/dd383571.aspx
我已经对其进行了修改以复制文件,但即使我将它与微软的示例完全相同,它仍然忽略了我放置在子目录中作为测试的文本文件......我很想知道这里发生了什么我以为“SearchOption.AllDirectories”可以解决这个问题……
{
string sourceDirectory = @"C:\Users\root\Desktop\bms 2013\bms 2013";
string archiveDirectory = @"C:\Users\root\Desktop\test";
try
{
var txtFiles = Directory.EnumerateFiles(sourceDirectory, "*.txt", SearchOption.AllDirectories);
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(sourceDirectory.Length + 1);
File.Copy(currentFile, Path.Combine(archiveDirectory, fileName));
}
}
catch (Exception)
{
// Console.WriteLine(e.Message);
}
}