(C# File) 文件操作
标签:
Get Files from Directory [C#]This example shows how to get list of file names from a directory (including subdirectories). You can filter the list by specific extension.
To get file names from the specified directory, use static method Directory.GetFiles. Lets have these files and subfolders in „c:\MyDir“ folder:
Get files from directoryMethod Directory.GetFiles returns string array with files names (full paths).
[C#]
using System.IO; string[] filePaths = Directory.GetFiles(@"c:\MyDir\"); // returns: // "c:\MyDir\my-car.BMP" // "c:\MyDir\my-house.jpg" Get files from directory (with specified extension)You can specify search pattern. You can use wildcard specifiers in the search pattern, e.g. „*.bmp“ to select files with the extension or „a*“ to select files beginning with letter „a“.
[C#]
string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp"); // returns: // "c:\MyDir\my-car.BMP" Get files from directory (including all subdirectories)If you want to search also in subfolders use parameter SearchOption.AllDirectories.
[C#]
string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp", SearchOption.AllDirectories); // returns: // "c:\MyDir\my-car.BMP" // "c:\MyDir\Friends\james.BMP"标签:
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/67380.html
- 上一篇:C#字符补位
- 下一篇:腾讯企业邮箱API实现单点登录和获取企业未读邮件