get path and filename from a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bob D
Posts: 20
Joined: 07 Sep 2011 18:32
Location: Eastern Australia

get path and filename from a variable

#1 Post by Bob D » 13 Dec 2012 04:39

I am so out of touch that I can't even think where to start plus I was never great at this. I will have a fully qualified file name (drive, path & filename) passed to my batch file as %1. The batch file and its parms will be started from a shortcut.

I need to split the string into the path and filename components. The string could include blanks as in C:\Program Files\IZArc\IZArc.exe and it will be enclosed in quotes. Using that as example I need to get C:\Program Files\IZArc in one variable and IZArc.exe in the other. The split is at the last backslash which can be discarded.

The execution environment is win 7 and win 8.

thanks...Bob

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: get path and filename from a variable

#2 Post by dbenham » 13 Dec 2012 06:34

path = %~dp1

file name = %~nx1

type HELP CALL from the command line for a complete description of all the available modifiers (listed at bottom of help)

Bob D
Posts: 20
Joined: 07 Sep 2011 18:32
Location: Eastern Australia

Re: get path and filename from a variable

#3 Post by Bob D » 13 Dec 2012 11:52

That worked well. Thanks for that.

Bob D
Posts: 20
Joined: 07 Sep 2011 18:32
Location: Eastern Australia

Re: get path and filename from a variable

#4 Post by Bob D » 17 Dec 2012 10:26

I felt embarrassed asking the original question in this thread but I haven't hit a keyboard in a long time and just could not see the easy way (which I knew would exist) to the answer. I'm just getting back into it all now. Thanks again. :D

Post Reply