[英]How can I check a list of folders exist in a given path
string[] folderPaths = new[]
{
"anim",
"audio",
"cleo",
"custom_models",
"data",
"libraries",
"models",
"modloader",
"movies",
"SAMP",
"text"
};
foreach (var folderPath in folderPaths)
{
string[] Liste = Directory.GetDirectories(gameFolder);
foreach (var item in Liste)
{
if (Directory.Exists(folderPath + item))
{
MessageBox.Show("All granted folders detected, you can join.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("A not granted folder has been detected, you cant join.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
雖然有所有已授予的文件夾,但我收到相同的錯誤:“已檢測到未授予的文件夾,您無法加入。”
我認為會是:
if (Directory.Exists(item + "\\" + folderPath))
這一行string[] Liste = Directory.GetDirectories(gameFolder);
將返回具有完整路徑的目錄,例如C:\\TEMP\\Publish
並且您在folderPath
變量中只有文件夾名稱。
這是完整的建議代碼:
string[] folderNames = new[]
{
"anim",
"audio",
"cleo",
"custom_models",
"data",
"libraries",
"models",
"modloader",
"movies",
"SAMP",
"text"
};
string gameFolder = @"D:\gta san andreas\";
foreach (var folderName in folderNames)
{
if (Directory.Exists(gameFolder + folderName))
MessageBox.Show(folderName + " Exists");
else
MessageBox.Show(folderName + " Not Exists");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.