フォルダからのファイル数

Directory.GetFiles を使用できます メソッド

Directory.GetFiles メソッド (文字列、文字列、SearchOption) も参照してください。

このオーバーロードで検索オプションを指定できます。

TopDirectoryOnly :現在のディレクトリのみを検索に含めます。

すべてのディレクトリ :現在のディレクトリとすべてのサブディレクトリを検索操作に含めます。このオプションには、マウントされたドライブやシンボリック リンクなどの再解析ポイントが検索に含まれます。

// searches the current directory and sub directory
int fCount = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length;
// searches the current directory
int fCount = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).Length;

System.IO.Directory myDir = GetMyDirectoryForTheExample();
int count = myDir.GetFiles().Length;

最も巧妙な方法は、LINQ を使用することです:

var fileCount = (from file in Directory.EnumerateFiles(@"H:\iPod_Control\Music", "*.mp3", SearchOption.AllDirectories)
                        select file).Count();