我正在尝试创建一个程序,该程序运行在 PC 上的所有驱动器并列出文件。 我的电脑中有 9 个驱动器,程序运行良好,并列出了所有驱动器上的文件,除了在我运行程序的驱动器上。 (哪个驱动器无关紧要。)
我有一个递归函数,它获取它找到的所有文件和目录并编译一个列表。
该函数在所有其他驱动器上运行良好,但对于我从中运行程序的驱动器,它显示 Could not find file 'D:\CreateFileList.deps.json'.
然后崩溃到该驱动器的 catch()。
这是执行此操作的代码部分。
static void DirSearch(string sDir,string file)
{
try
{
// Get files from root of the drive
if ( firstPass == 1 )
{
foreach (string f in Directory.GetFiles(sDir))
{
if (CheckExclusion(f))
{
WriteToFile(f,file);
}
}
firstPass = 0;
}
// Get files recursively
foreach (string d in Directory.GetDirectories(sDir))
{
if (CheckExclusion(d))
{
foreach (string f in Directory.GetFiles(d))
{
if (CheckExclusion(f))
{
WriteToFile(f,file);
}
}
}
DirSearch(d,file);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
显然这个文件不在驱动器的根目录下,而是与 .exe 文件在同一目录中。
有谁知道什么可能是错的?我的某些设置错误或包含或什么?