Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Answer already here. – CharlieRB Dec 20 '11 at 14:48
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. – Aaron Dec 20 '11 at 15:03

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