【发布时间】:2014-04-09 15:23:22
【问题描述】:
我有以下代码可以从 MyComputer 中检索所有 pdf 文件。但我收到如下错误。是否可以使用 C# 代码从一台计算机上检索所有 pdf 文件。
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(path); // Error : The path is not of a legal form.
IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.pdf", System.IO.SearchOption.AllDirectories);
【问题讨论】:
-
path 传递给
DirectoryInfo构造函数时的值是多少? -
错误只是说,您指定了非法路径。
-
您需要查看所有驱动器(请参阅stackoverflow.com/questions/781905/…),并在子文件夹中递归
-
我将路径设置为 MyComputer 文件夹/目录。字符串路径 = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
-
路径以“”的形式出现。所以它会引发错误。为什么路径对我来说是空的?
标签: c# c#-4.0 filesystems .net