+ Reply to Thread
Results 1 to 2 of 2

Thread: get the parent directory name of path

  1. #1

    get the parent directory name of path

    i have that sub-directory and i would like only to get it`s parent directory , for example :
    File path = C:\folder1\folder2\folder3

    What i would like only to know is folder2.

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    34
    You can use the below code to get the parent directory of a file.
    Code:
             
                DirectoryInfo dir = new DirectoryInfo(@"C:\folder1\folder2\folder3");
    
                Console.WriteLine(Directory.GetParent(dir.FullName).Name);

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts