如何获取目录的完整路径

奥雅纳

我已经在计算机的E驱动器中创建了一个目录名'DbInventory',现在在我的C#应用​​程序中,我想获得此Directoty(DbInventory)的完整路径。

在下面,我要提到的是我使用的代码

DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;

但是,此currentDirectoryName字符串返回C驱动器中的文件位置。

索纳·古努尔(Soner Gonul)

首先,DirectoryInfo构造函数将parameter作为具有完整path的字符串使用当您只写一个文件夹名称时,它将获得Visual Studio默认路径的位置,该位置在C:/驱动器和Bin/Debug文件夹最为常见

因此,在我的计算机中,您currentDirectoryName将是。

C:\Users\N53458\Documents\Visual Studio 2008\Projects\1\1\bin\Debug\DbInventory

如果要获取完整的路径名,则可以使用Path.GetDirectoryNamemethod。

返回指定路径字符串的目录信息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章