Page 1 of 1

How to get the current folder name ?

Posted: 10 Oct 2006 15:54
by budhax
Hello,
How to get the current folder name (not the full path) ?


In other words, how to get the last part of a string like
C:\folderA\folderB\folderC
using the bachslash delimiter "\"

Thanks.

Posted: 12 Oct 2006 23:37
by DosItHelp
budhax,

Try this:

Code: Select all

for %%a in ("%cd%") do set folder=%%~na
echo.%folder%

DOS IT HELP ? :wink:

Posted: 16 Oct 2006 12:22
by budhax
Thanks so much, it helps me.
I used it in this srcipt, to archive the folder contaning the BAT script:

Folder2RAR.bat

Code: Select all

FOR %%a in ("%CD%") DO SET CurFol=%%~na
CD..
WinRAR a "%CurFol%.RAR" "%CurFol%"


and I can use the same BATCH file for any folder.

Thank you.