开发者

C# - Problem while listing directories - DirectoryNotFoundException

I'm getting a "DirectoryNotFoundException" error, here is the code:

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.

I believe it's caused when it tries to parse the tilde part of that string Mísero. the directory D:\MUSICA\La Trampa - El Mísero Espiral De Encanto exists because I can see it 开发者_如何学JAVAand also have some files in it. Is there any way to send this string in correct way?

Thanks


Your code would not work to begin with, as you have illegal escape codes (\M and \L) in the string.

You need to escape you backslashes, or use a string literal:

string directorio = @"D:\MUSICA\La Trampa - El Mísero Espiral De Encanto";

Or:

string directorio = "D:\\MUSICA\\La Trampa - El Mísero Espiral De Encanto";

Otherwise the M from MUSICA is escaped as is the L from La. As I mentioned already these are not legal escape codes, as can be seen here.


Thanks for your answer, The problem was from other kind. The OS cannot delete that directory either, it says that the directory is not there while it is. This could be caused by a HD error. I'll try to fix it, but nothing has to do with my question. Thanks again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜