How to get the current folder name ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
budhax
Posts: 59
Joined: 09 Oct 2006 12:25

How to get the current folder name ?

#1 Post by budhax » 10 Oct 2006 15:54

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.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 12 Oct 2006 23:37

budhax,

Try this:

Code: Select all

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

DOS IT HELP ? :wink:

budhax
Posts: 59
Joined: 09 Oct 2006 12:25

#3 Post by budhax » 16 Oct 2006 12:22

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.

Post Reply