Wednesday, 1 August 2018

windows - Get current folder name by a DOS command?


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

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...