[C#] 目錄內檔案列表-依條件篩選

假設我要將目錄內的檔案全列出來,可以用下面的code

foreach (string filename in System.IO.Directory.GetFileSystemEntries(“c:\\awslive\\”))
{
       Console.WriteLine(filename);
}

那要加上一些篩選條件呢??可以用下面的code,

foreach (string filename in System.IO.Directory.GetFileSystemEntries(“d:\\awslive\\”,”*.mp4″))
{
       Console.WriteLine(filename);
 }

如果要查檔名符合條件的數量,也能這樣做

DirectoryInfo di = new DirectoryInfo(desFolder);
int transcodedFilesCount = di.GetFiles(file + “*.mp4”).Length;

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: 來玩C#