簡體   English   中英

獲取目錄下的子文件夾列表

[英]Get a list of the sub folders under a directory

好的,所以這是我目前的問題:

這是我的主要:

//System prompts user the type of archiving which will direct to the correct directory to set as root
Console.WriteLine("Enter the type of archiving you would like to do?");
string archivetype = Console.ReadLine(); 

//function that identifies which candidates to archive
Archive(archivetype, 20, 20);

//keep the application in debug mode
Console.ReadKey();

存檔方法:

//Archive method determines which directory to search in and how many versions to archive
static void Archive(string archivetype, int pversion, int version)
{
    //regex pattern to get folder names of the type #.#.#.#/#. something
    Regex reg = new Regex(@"\d+(\.\d+)+");
    //setting where to start looking
    DirectoryInfo root = new           DirectoryInfo(@"C:\Users\jphillips\Desktop\test\parent\ACE-3_0");
    var dirs = new List<DirectoryInfo>();
    //i want to make a recursive call to all the folders in my root directory to obtain all the folders with the regex pattern above that are not empty and do not have 3 files inside
    WalkDirectoryTree(root);      
}

終於走了directorytree方法

//so im using the walk directory tree on the microsoft website i need a way to have a sort of a global array to keep adding the directories that fit through the patterns mentioned above without resetting itself after each walkdirectorytree call
static void WalkDirectoryTree(System.IO.DirectoryInfo root)
{
    DirectoryInfo[] subDirs = null;

    // Now find all the subdirectories under this root directory.
    subDirs = root.GetDirectories();

    foreach (DirectoryInfo dir in subDirs)
    {
        //dirs is not global so it doesnt work here and i believe if i put a local array that it will reset itself everytime
        dirs = root.GetDirectories("*", SearchOption.TopDirectoryOnly).Where(d => reg.IsMatch(d.Name)).ToList();
        if()
        WalkDirectoryTree(dir);
    }
}

所以我現在真的迷失了,我想能夠調用walkdirectorytree遍歷我目錄的所有文件夾和子文件夾,以提取具有regex模式且不為空且tp內沒有3個文件的路徑給我這些文件夾路徑的列表。

您可以通過此GetDirectories重載在一個調用中獲得所有文件夾和子文件夾。

您傳遞了搜索字符串-不幸的是沒有傳遞正則表達式,並且SearchOption.AllDirectories作為第二個參數。 然后,您可以將結果通過正則表達式傳遞,以找到您感興趣的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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