Take the 2-minute tour ×

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.


I need to get scripts alone

share|improve this question

marked as duplicate by studiohack Dec 20 '11 at 15:15


Answer already here. –  CharlieRB Dec 20 '11 at 14:48

1 Answer 1

up vote 4 down vote accepted

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

for %%* in (.) do @echo %%~n*
share|improve this answer
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
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. –  BryceAtNetwork23 Dec 20 '11 at 15:03
