我已经在计算机的E驱动器中创建了一个目录名'DbInventory',现在在我的C#应用程序中,我想获得此Directoty(DbInventory)的完整路径。
在下面,我要提到的是我使用的代码
DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
但是,此currentDirectoryName字符串返回C驱动器中的文件位置。
首先,DirectoryInfo
构造函数将parameter作为具有完整path的字符串使用。当您只写一个文件夹名称时,它将获得Visual Studio默认路径的位置,该位置在C:/
驱动器和Bin/Debug
文件夹下最为常见。
因此,在我的计算机中,您currentDirectoryName
将是。
C:\Users\N53458\Documents\Visual Studio 2008\Projects\1\1\bin\Debug\DbInventory
如果要获取完整的路径名,则可以使用Path.GetDirectoryName
method。
返回指定路径字符串的目录信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句