我正在尝试读取文件以获取路径,然后搜索该路径。
C:\Users\Public\Documents\ScriptPath.txt 包含“C:\Users\Public\Music 文件夹\”
这是我的代码
string ScriptPath = System.IO.File.ReadAllText(@"C:\Users\Public\Documents\ScriptPath.txt");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(ScriptPath);
System.Threading.Thread.Sleep(2000);
foreach (System.IO.FileInfo file in dir.GetFiles("*.*"))
{
MessageBox.Show("{0}, {1}" + file.Name+ file.Length);
}
我得到的错误是这个。
ArgumentException 未处理
mscorlib.dll 中出现“System.ArgumentException”类型的未处理异常
附加信息:路径中的非法字符。
如果有人可以帮助理解为什么这不起作用,我将不胜感激。