C# 移动路径包含无效字符
C# move path includes invalid characters
我一直在尝试在 c# 中为 2 个不同的路径做一个重命名程序,但我不断收到错误 "Path includes invalid characters" 我不知道如何修复它,我尝试添加 @ 并删除 \ 和只保留一个。但是还没想好怎么解决。希望得到任何帮助。
这就是给我错误的原因:
if (French.Checked)
{
directoryfile = @"C:\Users\" + curruser + @"\Appdata\Local\fo4renamer\directory.txt";
label1.Text = directoryfile;
readpath = File.ReadAllText(directoryfile);
string shouldwork = readpath + "data";
string french = shouldwork + "\french";
string german = shouldwork + "\german";
string tmp = shouldwork + "tmp.txt";
label1.Text = french;
string path2 = @"C:\Users\duchacekda\Desktop\e\Renamer\Renamer\bin\Debug\tmp.txt";
string filename = @"C:\Users\duchacekda\Desktop\e\Renamer\Renamer\bin\Debug\french.txt";
File.Move(french, german);
}
完整代码如下:
https://pastebin.com/0i7fzh24
编辑:这是 curruser 的字符串
string curruser = System.Environment.UserName;
这一行给出了异常
File.Move(french, german);
File.ReadAllText Method (String) :打开一个文本文件,读取文件的所有行,然后关闭文件。
所以在你的场景中:
string french = (Content of directory.txt) + "data" + "\french";
取决于directory.txt
的内容
a) 如果content = directory path(c:\foo) 没有问题
b) 如果 content = "dummy text *** dummy text" 那么它会抛出异常
请检查文件内容
发现错误,我用的是 WriteLine 而不是 Write 所以它在行的末尾添加了 enter 导致路径不正确,感谢帮助
我一直在尝试在 c# 中为 2 个不同的路径做一个重命名程序,但我不断收到错误 "Path includes invalid characters" 我不知道如何修复它,我尝试添加 @ 并删除 \ 和只保留一个。但是还没想好怎么解决。希望得到任何帮助。
这就是给我错误的原因:
if (French.Checked)
{
directoryfile = @"C:\Users\" + curruser + @"\Appdata\Local\fo4renamer\directory.txt";
label1.Text = directoryfile;
readpath = File.ReadAllText(directoryfile);
string shouldwork = readpath + "data";
string french = shouldwork + "\french";
string german = shouldwork + "\german";
string tmp = shouldwork + "tmp.txt";
label1.Text = french;
string path2 = @"C:\Users\duchacekda\Desktop\e\Renamer\Renamer\bin\Debug\tmp.txt";
string filename = @"C:\Users\duchacekda\Desktop\e\Renamer\Renamer\bin\Debug\french.txt";
File.Move(french, german);
}
完整代码如下: https://pastebin.com/0i7fzh24
编辑:这是 curruser 的字符串
string curruser = System.Environment.UserName;
这一行给出了异常
File.Move(french, german);
File.ReadAllText Method (String) :打开一个文本文件,读取文件的所有行,然后关闭文件。
所以在你的场景中:
string french = (Content of directory.txt) + "data" + "\french";
取决于directory.txt
的内容a) 如果content = directory path(c:\foo) 没有问题
b) 如果 content = "dummy text *** dummy text" 那么它会抛出异常
请检查文件内容
发现错误,我用的是 WriteLine 而不是 Write 所以它在行的末尾添加了 enter 导致路径不正确,感谢帮助