簡體   English   中英

如何檢查給定路徑中存在的文件夾列表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM