7

Possible Duplicate:
Get current folder name by a DOS command?

In my batch file, I have,

SET currentFolder=%CD%
echo "%currentFolder%"

Prints the whole directory path.

C:\www\scritps\

I need to get scripts alone

Raj
  • 483
  • 4
  • 9
  • 15
  • 1
    Answer already [here](http://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command). – CharlieRB Dec 20 '11 at 14:48

1 Answers1

8

There really isn't an easy way to do it. This works in a .bat file:

for %%* in (.) do @echo %%~n*
Aaron
  • 760
  • 1
  • 7
  • 12
  • that's fantastic (of course, * can be replaced with a letter), out of interest, howcome you used * ? btw, FWIW for any that don't know, # and ? work too. %%? and %%# – barlop Dec 20 '11 at 14:44
  • 1
    I didn't want to use something like "x" (or another letter) because I didn't want the original poster to get confused at the "~nx" part. But you're right, you could substitute any letter there. Coding in DOS .bat is so archaic that it's sometimes difficult to see what's going on. – Aaron Dec 20 '11 at 15:03
  • 1
    This doesn't play well with directories that use `.` in their names. Any tips? – kayleeFrye_onDeck Jan 11 '17 at 01:07
  • @kayleeFrye_onDeck see answers for directions with spaces, periods, etc., in https://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command – Micah Lindström Jun 03 '23 at 13:34