Get current folder name instead of current path in windows batch file

6

2

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

Lenin Raj Rajasekaran

Posted 2011-12-20T13:24:10.463

Reputation: 423

Question was closed 2011-12-20T15:15:38.733

Answer already here.

– CharlieRB – 2011-12-20T14:48:03.817

Answers

7

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

for %%* in (.) do @echo %%~n*

Aaron

Posted 2011-12-20T13:24:10.463

Reputation: 752

This doesn't play well with directories that use . in their names. Any tips? – kayleeFrye_onDeck – 2017-01-11T01:07:37.263

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 – 2011-12-20T14:44:02.483

1I 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 – 2011-12-20T15:03:20.533