Parse path into drive/directory/file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
Bitmap321
Posts: 2
Joined: 05 Jan 2009 15:37
Location: Seattle

Parse path into drive/directory/file

#1 Post by Bitmap321 » 05 Jan 2009 15:44

I have a string %str%=c:\parentdir\childdir\filename.ext
I wont know in advance the length of parentdir,childdir, or filename nor will i know the drive letter

How can i break this out into
c:
c:\parentdir
c:\parentdir\childdir
filename.ext

Thanks,

jeb
Expert
Posts: 1042
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 05 Jan 2009 17:19

Hi jpeg,

look at the help of FOR (for /?), there is the substitution explained.

Code: Select all

setlocal 

set str=c:\parentdir\childdir\filename.ext

call :split %str%
goto :eof

:split
echo drive=%~d1 path=%~p1 name=%~n1 ext=%~x1
goto :eof


Results to

Code: Select all

drive=c: path=\parentdir\childdir\ name=filename ext=.ext


jeb

Bitmap321
Posts: 2
Joined: 05 Jan 2009 15:37
Location: Seattle

#3 Post by Bitmap321 » 06 Jan 2009 13:38

Thanks jeb

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Parse path into drive/directory/file

#4 Post by darioit » 20 Jun 2013 01:24

hello,

how to put in a variable only this directory "childdir" ?

Regards

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse path into drive/directory/file

#5 Post by foxidrive » 20 Jun 2013 01:45

Start a new thread - don't reopen old threads.

Explain your request a little better too.

Locked