【发布时间】:2013-09-10 15:28:02
【问题描述】:
我有以下代码:
private string[] FindExistingDocuments()
{
string supportedImageFormats = "jpg,pdf,doc,docx,xlsx";
DirectoryInfo documentPath = new DirectoryInfo("...");
string supportedFileTypes = String.Join(",*.", supportedImageFormats.Split(','));
string[] files = Directory.GetFiles(documentPath.FullName, supportedFileTypes, SearchOption.AllDirectories);
return files;
}
作为搜索特定文件类型列表的一种方式,但当前代码的问题是String.Join 没有将分隔符放在第一项(这是有道理的)。
所以我的supportedFileTypes 原来是:
jpg,*.pdf,*.doc,*.docx,*.xlsx
但我希望它是:
*.jpg,*.pdf,*.doc,*.docx,*.xlsx
我可以用一种非常干净的方式制作这个吗?
注意:我无法更改supportedImageFormats的内容
【问题讨论】:
标签: c# string join split getfiles