Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get directory name from path of %CD%

Tags:

batch-file

cmd

Given that the current directory, %CD% is

C:\Parent\Child

In a batch file, how can I get the value Child in to a variable?

thanks

like image 408
Valamas Avatar asked Nov 09 '11 20:11

Valamas


People also ask

How can I get a directory name?

Get the directory name with dirname() PHP's dirname() function returns just the directory part of the full path. This is done by simply excluding the last section of the full path based on the directory separator (/ on *nix based filesystems and on Windows) and no check is done to see if it's actually a directory.

How do I get the filename from the file path?

To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);

How do I get the path of a directory in Python?

To retrieve a file in Python, you need to know the exact path to reach the file, in Windows, you can view a particular file's path by right-clicking the File-> Properties-> General-> Location. Similarly, to run a script, the working directory needs to be set to the directory containing the script.


2 Answers

for %%a in (.) do set currentfolder=%%~na
echo %currentfolder%

From here: https://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command

like image 55
manojlds Avatar answered Nov 16 '22 01:11

manojlds


Here is the answer

for %%a in ("%cd%") do set folder=%%~na
echo.%folder%
pause
like image 28
Valamas Avatar answered Nov 16 '22 01:11

Valamas