2
4

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#で指定したディレクトリ内のファイル一覧を取得する。

Last updated at Posted at 2015-07-30

目的

ディレクトリ内のファイル一覧を取得します。
できればファイル名で絞り込みます。

手段

Directory.GetFiles メソッド (String, String)を使います。

ソースコード

// 第一引数で対象のディレクトリを指定
// 第二引数でファイルのパターンを指定
var files = Directory.GetFiles(@"C:\", "*.xls");
files.ToList().ForEach(name => Console.WriteLine(name));

第二引数のファイルのパターンは

    • : 空文字か複数文字
  • ? : 空文字か一文字

実行結果

C:\TEST①.xlsx
C:\TEST②.xlsx

こんな感じです。
フルパスの文字列が取得できます。

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?