3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【C#】ディレクトリを再帰的に探索する【技術メモ】

Posted at

指定したディレクトリ及びそのサブディレクトリ内のファイルに対して処理を実行したいときに使う。

/// <summary>
/// ディレクトリを再帰的に探索します。
/// </summary>
/// <param name="directoryName">探索するディレクトリのルート。</param>
private static void RecursivelySearchingDirectories(string directoryName)
{
    Directory
        .GetFiles(directoryName)
        .Where(/* 処理対象のファイルを抽出 */)
        .ToList()
        .ForEach(/* 実行したい処理 */);
    Directory
        .GetDirectories(directoryName)
        .ToList()
        .ForEach(RecursivelySearchingDirectories);
}
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?