c# 为什么当路径是“C:”时DirectoryInfo 将我带到应用程序文件夹?
为什么当我给出路径“c:”时它直接将我更改为应用程序文件夹?
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo("c:");
Console.WriteLine(dir.FullName);
Console.ReadLine();
}
输出如下:
c:\users...\documents\Visual Studio 2010\projects\consoleApplication9\bin\debug
但是当我给出 @"c:\"
时,它会转到磁盘 c:
尽管 "d:"
和 @"d:\"
会写入磁盘 d:
。
所以我需要一种方法让 "c:"
保存到磁盘 c:
提前致谢!
Why when i give the path "c:" it changed me directly to application folder?
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo("c:");
Console.WriteLine(dir.FullName);
Console.ReadLine();
}
The output is the following:
c:\users...\documents\visual studio
2010\projects\consoleApplication9\bin\debug
But when I give @"c:\"
it goes to disk c:
despite that "d:"
and @"d:\"
takes to disk d:
.
So I need a way to let "c:"
takes to disk c:
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
"c:"
表示“C 驱动器上的当前目录”,而@"c:\"
表示“C 驱动器的根目录”。这与命令提示符下的工作方式相同......Just
"c:"
means "the current directory on the C drive" whereas@"c:\"
means "root of the C drive". This works the same way from a command prompt...C: 只是卷说明符,因此它将更改为该卷上的当前路径,这将是应用程序的工作路径。
D:将您带到根目录只是因为该卷的当前文件夹恰好位于根目录。
C: is just the volume specifier, so it will change to your current path on that volume, which would be the working path of the application.
D: takes you to root simply because your current folder for that volume happens to be at root.
使用以下
在执行 c 时 基本目录:应用程序不理解这一点,因此它返回应用程序启动/运行的目录。
请注意 dir = {.} 如果您传入文字目录路径,您将获得预期的结果。
Use the following
The Base Directory at the time when you do c: the application doesn't understand that so it returns the Directory of where the application was launched / run from.
Notice that dir = {.} if you would have passed in a literal directory path you would have gotten the expected results..