它非常奇怪,因为程序正在迭代文件!outfolder 和 infolder 都在 H:/ 我使用 windows 7 的外部 HD 中。这个想法是移动所有仅包含扩展名为 db 和 svn-base 的文件的文件夹。当我尝试移动文件夹时出现异常。VS2010 告诉我找不到 dir 中指定的文件夹。这段代码正在遍历 dir 所以它怎么找不到它!这很奇怪。
string []theExt = new string[] { "db", "svn-base" };
foreach (var dir in Directory.GetDirectories(infolder))
{
bool hit = false;
if (Directory.GetDirectories(dir).Count() > 0)
continue;
foreach (var f in Directory.GetFiles(dir))
{
var ext = Path.GetExtension(f).Substring(1);
if(theExt.Contains(ext) == false)
{
hit = true;
break;
}
}
if (!hit)
{
var dst = outfolder + "\\" + Path.GetFileName(dir);
File.Move(dir, outfolder); //FileNotFoundException: Could not find file dir.
}
}
}