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

1
  • 1
    Answer already here.
    – CharlieRB
    Commented Dec 20, 2011 at 14:48

1 Answer 1

8

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

for %%* in (.) do @echo %%~n*
4
  • 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
    Commented Dec 20, 2011 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
    Commented Dec 20, 2011 at 15:03
  • 1
    This doesn't play well with directories that use . in their names. Any tips? Commented Jan 11, 2017 at 1:07
  • @kayleeFrye_onDeck see answers for directions with spaces, periods, etc., in superuser.com/questions/160702/… Commented Jun 3, 2023 at 13:34

Not the answer you're looking for? Browse other questions tagged .