我收到"DirectoryNotFoundException"错误,这里是代码:
string directorio = "D:\MUSICA\La Trampa - El Mísero Espiral De Encanto";
DirectoryInfo dir = new DirectoryInfo(directorio);
DirectoryInfo[] dirs = dir.GetDirectories(); <------------This is the line I'm having this problem.
Run Code Online (Sandbox Code Playgroud)
我相信它是在它试图解析该字符串的波浪部分时引起的Mísero.该目录D:\MUSICA\La Trampa - El Mísero Espiral De Encanto存在,因为我可以看到它,并且还有一些文件.有没有办法以正确的方式发送这个字符串?
谢谢
您的代码无法开始,因为您在字符串中有非法的转义码(\M和\L).
你需要逃避反斜杠,或使用字符串文字:
string directorio = @"D:\MUSICA\La Trampa - El Mísero Espiral De Encanto";
Run Code Online (Sandbox Code Playgroud)
要么:
string directorio = "D:\\MUSICA\\La Trampa - El Mísero Espiral De Encanto";
Run Code Online (Sandbox Code Playgroud)
否则,Mfrom将MUSICA被转义为Lfrom La.正如我已经提到的这些都是不合法的转义码,可以看出这里.