赋值函数“Directory.GetFiles”结果为字符串数组

时间:2014-03-02 14:45:54

标签: c#

我想使用这样的字符串将函数“Directory.GetFiles”结果赋给字符串数组:

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

folderParh包含:“D:\ Images \ Wallpapers \ 1600-900”。

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

1 个答案:

答案 0 :(得分:3)

您的搜索模式应为*.jpg,请尝试以下操作:

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

看看documentation

  

* (asterisk): 该位置的零个或多个字符。

相关问题