Get current folder name in Windows Command Prompt
Get the current folder name (not full path) in Windows Command Prompt.
Variant 1
FOR %G IN (.) DO ECHO %~NXG
Batch file contents:
@ECHO OFF
FOR %%G IN (.) DO (
ECHO %%~NXG
)
Variant 2
FOR /F "DELIMS=\" %G IN ("%CD%") DO ECHO %~NXG
Batch file contents:
@ECHO OFF
FOR /F "DELIMS=\" %%G IN ("%CD%") DO (
ECHO %%~NXG
)
Links
- Get current folder name by a DOS command? superuser.com/questions/160702/get-current-folder-name-by-a-dos-command#answer-160712
- Get current folder name by a DOS command? superuser.com/questions/160702/get-current-folder-name-by-a-dos-command#answer-358416
- The FOR command: Windows NT 4/Windows 2000 Syntax robvanderwoude.com/ntfor.php
Operating systems
- Windows
More
- Count the number of lines in a file in Windows Command Prompt
- Create a set of subfolders in each of multiple folders (Windows)
- Create multiple folders at once in Windows Command Prompt
- Get full path to the current directory in DOS and Windows Command Prompt
- Listing only folder names with DIR command