mameesh
mameesh

Reputation: 3761

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?

Upvotes: 0

Views: 160

Answers (2)

Kenny Evitt
Kenny Evitt

Reputation: 9791

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

Upvotes: 1

SLaks
SLaks

Reputation: 887415

You're looking for the directory.Parent property.

Upvotes: 2

Related Questions