Page 1 of 1

get path and filename from a variable

Posted: 13 Dec 2012 04:39
by Bob D
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

Re: get path and filename from a variable

Posted: 13 Dec 2012 06:34
by dbenham
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)

Re: get path and filename from a variable

Posted: 13 Dec 2012 11:52
by Bob D
That worked well. Thanks for that.

Re: get path and filename from a variable

Posted: 17 Dec 2012 10:26
by Bob D
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