2016-05-24 6 views
0

をサブフォルダのリストを取得します。ので、これは現在、私の問題であるディレクトリの下の[OK]を

これが私のメインです:

//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);  
} 

歩きますディレクトリツリーメソッド

//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を呼び出して、私のディレクトリのすべてのフォルダとサブフォルダを再帰的に呼び出すことができるようにしたいのですが、正規表現のパターンを持つファイルを解読するためにrecursevelyとtp内に3つのファイルがありませんこれらのフォルダパスのリスト。

答えて

1

このオーバーロードがGetDirectoriesの1回のコールですべてのフォルダとサブフォルダを取得できます。

残念ながら正規表現ではなく、SearchOption.AllDirectoriesを第2引数として渡します。結果を正規表現に渡して、あなたが興味のあるものを見つけ出すことができます。

+0

これは私が何をするつもりですか?dirs = root.GetDirectories( "*"、SearchOption.AllDirectories).Where(d => (w => w);を選択します。 – PhillipsJP

+0

を選択すると、フォルダの末尾にTESTSがある場合など、どのように削除しますか?通常のフォーマットは4.3.2.4ですが、いくつかのフォルダには4.45.3.3_TESTSがあります。 – PhillipsJP

+0

@PhillipsJPその場合の正規表現を取得することは、別の質問の価値があるかもしれません。 – ChrisF

関連する問題