Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get directory from full path

Tags:

If i have:

C:\temp\foo\bar\

(NOTE: bar is a directory)

how can i parse out:

bar

like image 598
leora Avatar asked Mar 22 '09 10:03

leora


People also ask

How can I get a full directory of files?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How do I get the directory from a file's full path Python?

To get current file's full path, you can use the os. path. abspath function. If you want only the directory path, you can call os.

How do I find the full directory in Linux?

The best Linux command to get file path is using pwd command. To use this command, type “pwd” into your terminal and press enter. This command will print the current working directory. The output will be the file path.

What is the full path to the directory?

The full path name is the path from the root directory (i.e., / ). ./my_script is the relative path name, because the path is given relatively to the current directory, which is denoted by . . So if you are in your home directory the full path is s.th.


2 Answers

I figured it out.

DirectoryInfo info = new DirectoryInfo(sourceDirectory_); string currentDirectoryName = info.Name; 
like image 181
leora Avatar answered Sep 28 '22 09:09

leora


Try

System.IO.Path.GetFileName("C:\\temp\\foo\\bar"); 
like image 26
Program.X Avatar answered Sep 28 '22 09:09

Program.X