ディレクトリとサブディレクトリ内のすべてのファイルとディレクトリを一覧表示する 質問する

ディレクトリとサブディレクトリ内のすべてのファイルとディレクトリを一覧表示する 質問する

ディレクトリとそのディレクトリのサブディレクトリに含まれるすべてのファイルとディレクトリを一覧表示したいです。ディレクトリとして C:\ を選択した場合、プログラムは、アクセス可能なハード ドライブ上のすべてのファイルとフォルダの名前を取得します。

リストは次のようになります

テキスト
テキスト
fd\a\
fd\b\
fd_a_1.txt ファイル
fd\a\2.txt
\ d\ a\ a\
\ d\ a\ b\
fd_b_1.txt ファイル
fd\b\2.txt
\ d\ b\ a \ n
\ d\ b\ b
fd\a\a\1.txt
\ d\ a\ a\ a\
fd\a\b\1.txt
\ d\ a\ b\ a
fd\b\a\1.txt
\ d\ b\ a\ a\
fd\b\b\1.txt
\ d\ b\ b\ a \ d ...

ベストアンサー1

string[] allfiles = Directory.GetFiles("path/to/dir", "*.*", SearchOption.AllDirectories);

*.*ファイルに一致するパターンはどこにあるか

ディレクトリも必要な場合は、次のようにします。

 foreach (var file in allfiles){
     FileInfo info = new FileInfo(file);
 // Do something with the Folder or just add them to a list via nameoflist.add();
 }

おすすめ記事