Page 1 of 1

Parent folder path from file path

Posted: 08 Apr 2012 17:06
by MrKnowItAllxx
I'm looking for something similar to %~fI (assuming a for variable 'I' with the file name), but a way to get only the path to the parent folder of the file.

so "C:\My Docs\file1.docx" would be translated to "C:\My Docs"

Re: Parent folder path from file path

Posted: 08 Apr 2012 17:09
by MrKnowItAllxx
-.-.... found my answer practically right after I posted this, my apologies "%~pI"

Re: Parent folder path from file path

Posted: 08 Apr 2012 17:28
by Fawers
You can also add a 'd' to that variable.

Code: Select all

%~dpI

%~pI will return the path only. Adding that extra 'd' will give you the drive letter as well.

Re: Parent folder path from file path

Posted: 08 Apr 2012 17:34
by Squashman
MrKnowItAllxx wrote:-.-.... found my answer practically right after I posted this, my apologies "%~pI"

Did you read the FOR command help?

Re: Parent folder path from file path

Posted: 08 Apr 2012 19:41
by MrKnowItAllxx
Yessir, I had been reading it before I even posted, but I somehow missed it whenever I was looking over everything =P

Re: Parent folder path from file path

Posted: 08 Apr 2012 21:08
by Fawers
MrKnowItAllxx wrote:Yessir, I had been reading it before I even posted, but I somehow missed it whenever I was looking over everything =P


Whenever you want to know about those "variable custom settings", you can take look both at the FOR command help and/or CALL command help.
The only difference between them both is that FOR deals with a variable, while CALL deals with parameters.

However, they're pretty much the same. Look:
(I'll try my best to translate from my language to English)

FOR

Code: Select all

%~I         - expands %I and removes any quotes (") on it
%~fI        - expands %I to a full, qualified path
%~dI       - expands %I to a drive letter
%~pI       - expands %I to a path
%~nI       - expands %I to a file name
%~xI       - expands %I to a file extension
%~sI       - expands %I to a short path and file name
%~aI       - expands %I to file attributes
%~tI         - expands %I to file date and time
%~zI        - expands %I to file size
%~$PATH:I   - [this one's explanation doesn't make sense in my
         language, let's just ignore it]


CALL

Code: Select all

%~1         - expands %1 and removes any quotes (") on it
%~f1        - expands %1 to a full, qualified path
%~d1       - expands %1 to a drive letter
%~p1       - expands %1 to a path
%~n1       - expands %1 to a file name
%~x1       - expands %1 to a file extension
%~s1       - expands %1 to a short path and file name
%~a1       - expands %1 to file attributes
%~t1         - expands %1 to file date and time
%~z1        - expands %1 to file size
%~$PATH:1   - [same here]