KOMPX.COM or COMPMISCELLANEA.COM   

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

  1. Get current folder name by a DOS command? superuser.com/questions/160702/get-current-folder-name-by-a-dos-command#answer-160712
  2. Get current folder name by a DOS command? superuser.com/questions/160702/get-current-folder-name-by-a-dos-command#answer-358416
  3. The FOR command: Windows NT 4/Windows 2000 Syntax robvanderwoude.com/ntfor.php
Operating systems
More