【发布时间】:2017-03-14 02:13:39
【问题描述】:
private static void saveDirAndFiles(TreeNode currNode)
{
using (StreamWriter file = new StreamWriter("test.html"))
{
if(currNode.ValueType=="DIR") //Are you a File or Directory
{
file.WriteLine(currNode.Value);//relative Name of Directory
}
else
{
string[] file1 = File.ReadAllLines(Path.GetFullPath(currNode.Value)); //EXEPTION
string prgcode = "";
foreach (string line in file1)
{
prgcode += line;
}
file.WriteLine(currNode.Value);//relative Name of File +...
file.WriteLine(String.Format("<code><pre>{0}</pre></code>", prgcode)); //... The Content of the File
}
}
foreach (TreeNode item in currNode.ChildNodes)
{
saveDirAndFiles(item);
}
}
该函数仅在我当前正在处理的项目中搜索绝对路径。我的项目在桌面上,文件名在 C 目录上。异常说:找不到 Project\bin\debug\Filename。
【问题讨论】:
-
Path.GetFullPath不搜索驱动器。 Read the documentation. 即使搜索到了,如果在两个不同的目录中有两个名为“Filename”的文件怎么办?您需要从用户或配置文件中获取目录的名称。
标签: c# file directory filepath