简体   繁体   中英

How to get just folder path without the actual folder name?

I am wondering how I can get the file path, 1 level above the folder passed into a string.

So I have the following code:

 foreach (DirectoryInfo directory in rootDir.GetDirectories())
  {
     string test = directory.FullName;
  }

This returns the directory name including the folder name so it is returning this:

c:\\test\\FolderName

Where FolderName is the name of the directory object.

How would I get only c:\\test?

您正在寻找directory.Parent属性

string test = Path.GetDirectoryName(directory.FullName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM