Discussion:
up two folders in a batch file
(too old to reply)
Greg Stigers
2009-10-19 17:06:28 UTC
Permalink
I'm using %~dP0 to identify the path from which a batch file is run. I need
to write a log, up two levels, and then down two folders. And I need to let
the user know exactly where that is.

I can code %~dP0..\..\dir\subdir, but don't expect the user to understand
what that means. I've toyed with a couple of ideas, all kludgy and obtuse.
Is there a way way to do this, that isn't ugly?
______
Greg Stigers, MCSE
remember to vote for the answers you like
Tom Lavedas
2009-10-19 18:02:31 UTC
Permalink
Post by Greg Stigers
I'm using %~dP0 to identify the path from which a batch file is run. I need
to write a log, up two levels, and then down two folders. And I need to let
the user know exactly where that is.
I can code %~dP0..\..\dir\subdir, but don't expect the user to understand
what that means. I've toyed with a couple of ideas, all kludgy and obtuse.
Is there a way way to do this, that isn't ugly?
______
Greg Stigers, MCSE
remember to vote for the answers you like
Have you considered something like this ...

for %%a in ("%~dp0\..") do set folder=%%~dpadir\subdir
echo %folder%
_____________________
Tom Lavedas
Greg Stigers
2009-10-19 19:43:24 UTC
Permalink
I know about %~dp0, but not %~dpa. Can you explain that one a bit? Web
searching on ~ is disappointing.
Post by Tom Lavedas
Have you considered something like this ...
for %%a in ("%~dp0\..") do set folder=%%~dpadir\subdir
echo %folder%
_____________________
Tom Lavedas
Tom Lavedas
2009-10-19 20:04:49 UTC
Permalink
Post by Greg Stigers
I know about %~dp0, but not %~dpa. Can you explain that one a bit? Web
searching on ~ is disappointing.
Post by Tom Lavedas
Have you considered something like this ...
 for %%a in ("%~dp0\..") do set folder=%%~dpadir\subdir
 echo %folder%
_____________________
Tom Lavedas
The specific implementation used is based in the FOR statement. The
variable I used was %%a, so the syntax is analogous to that of the
replaceable argument, %0, that you used. For more information, see
the help for FOR (FOR/? at a command prompt).
_____________________
Tom Lavedas
Al Dunbar
2009-10-20 02:41:11 UTC
Permalink
Post by Greg Stigers
I'm using %~dP0 to identify the path from which a batch file is run. I
need to write a log, up two levels, and then down two folders. And I need
to let the user know exactly where that is.
I can code %~dP0..\..\dir\subdir, but don't expect the user to understand
what that means. I've toyed with a couple of ideas, all kludgy and obtuse.
Is there a way way to do this, that isn't ugly?
______
Greg Stigers, MCSE
remember to vote for the answers you like
This should do the trick for you, assuming that the batch file is being run
from a real or mapped drive rather than from a UNC:


pushd %~dP0..\..\dir\subdir
(set logFileFolder=%cd%)
popd
echo/look for the log file here: "%lofFileFolder%"

/Al

Loading...