Parent folder path from file path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Parent folder path from file path

#1 Post by MrKnowItAllxx » 08 Apr 2012 17:06

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"

MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Re: Parent folder path from file path

#2 Post by MrKnowItAllxx » 08 Apr 2012 17:09

-.-.... found my answer practically right after I posted this, my apologies "%~pI"

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Parent folder path from file path

#3 Post by Fawers » 08 Apr 2012 17:28

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.

Squashman
Expert
Posts: 4119
Joined: 23 Dec 2011 13:59

Re: Parent folder path from file path

#4 Post by Squashman » 08 Apr 2012 17:34

MrKnowItAllxx wrote:-.-.... found my answer practically right after I posted this, my apologies "%~pI"

Did you read the FOR command help?

MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Re: Parent folder path from file path

#5 Post by MrKnowItAllxx » 08 Apr 2012 19:41

Yessir, I had been reading it before I even posted, but I somehow missed it whenever I was looking over everything =P

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Parent folder path from file path

#6 Post by Fawers » 08 Apr 2012 21:08

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]

Post Reply