Is it possible to get the current folder name (not current directory path) by using a DOS command? If so, how?
The closest I got was this but it doesn't do it:
for /f "delims=\" %%a in ("%CD%") do set CURR=%%a
echo.DIR: %CURR%
note: the above attempt was me attempting to tokenize the string and get the last token set as the CURR variable.
Answer
Shortest way I have found:
for %I in (.) do echo %~nxI
or within a .bat script:
for %%I in (.) do echo %%~nxI
or in .bat with Get value in variable.
for %%I in (.) do set CurrDirName=%%~nxI
echo %CurrDirName%
Explanation: http://www.robvanderwoude.com/ntfor.php
nx means file name and extension only
No comments:
Post a Comment