0

How to get just the name of a folder without path from full folder path in 8.3 format?

How can I get the just the name of the target folder under Windows command line?

I have folder strings like these:

C:\Users\Fred\DOCUME~1
C:\Users\Fred\Music
C:\Users\Fred\DOWNLO~1\FREEDO~1

How can I get just the target folder name using a batch script to get:

FREEDO~1
Music
DOCUME~1
Mofi
  • 46,139
  • 17
  • 80
  • 143
  • 2
    Possible duplicate of [How to split the filename from a full path in batch?](http://stackoverflow.com/questions/9252980/how-to-split-the-filename-from-a-full-path-in-batch) – stdob-- May 09 '16 at 04:18
  • `for /R C:\Users\Fred /D %%D in (*) do echo %%~snxD` returns all folders in `C:\Users\Fred` in short-name (8.3) format recursively; this will also return `DOWNLO~1` with your example folder structure... – aschipfl May 09 '16 at 08:03

1 Answers1

1
dir /ad /b C:\Users\Fred

or

cd C:\Users\Fred
for /f "delims=" %A in ('dir /ad /b C:\Users\Fred') do Echo Path is %~dpA Name is %~nA

See dir /? and for /?

  • Noodles, thank you for responding. But you misunderstood. This isn't a directory question. I am using a string and want the last folder of the string given. – FredMcD May 09 '16 at 18:26