2014-03-02 46 views
1

我想用这种串分配功能 “Directory.GetFiles” 结果字符串数组:赋值函数 “Directory.GetFiles” 结果字符串数组

string[] allFoundFiles = Directory.GetFiles(@folderPath, ".jpg", SearchOption.AllDirectories); 

folderParh包括:“d:\ IMAGES \壁纸\ 1600-900" 。

但作为一个结果,我得到一个空字符串数组(allFoundFiles)。 JPG图片包含在所需的路径中。我的错误在哪里?

+0

有了'.jpg',这种方法searchs正是这种命名的文件。用'* .jpg',你说那个文件中可能有零个或多个字符。例如,字符串“* .jpg”搜索以“.jpg”结尾的路径中的所有名称阅读文档http://msdn.microsoft.com/en-us/library/ms143316(v=vs.110)的.aspx –

回答

3

你的搜索模式应该是*.jpg,试试这个:

string[] allFoundFiles = Directory.GetFiles(@folderPath, "*.jpg", SearchOption.AllDirectories); 

documentation看看:在这个位置

* (asterisk):零个或多个字符。