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
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.
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);
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.
for %%a in (.) do set currentfolder=%%~na
echo %currentfolder%
From here: https://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command
Here is the answer
for %%a in ("%cd%") do set folder=%%~na
echo.%folder%
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With