Get current folder name instead of current path in windows batch file
16,974
There really isn't an easy way to do it. This works in a .bat file:
for %%* in (.) do @echo %%~n*
Related videos on Youtube
Author by
Lenin Raj Rajasekaran
Updated on September 18, 2022Comments
-
Lenin Raj Rajasekaran 3 monthsPossible 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
scriptsalone-
CharlieRB about 11 yearsAnswer already here.
-
-
barlop about 11 yearsthat'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 %%# -
Aaron about 11 yearsI 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. -
kayleeFrye_onDeck almost 6 yearsThis doesn't play well with directories that use.in their names. Any tips?