windows - Starting batch file command prompt from the directory location in which the batch file resides in -
i writing batch file uses of files within it's parent directory (lets folder1).
c:\user\steve\foder1\
now want make whole folder_1 relocatable can copy paste folder anywhere on my/someone else's computer , run batch script.
d:\user\random_guy\folder1\
the question how start batch file's command prompt (d:\user\random_guy\folder1) it's parent directory without writing batch script that.
start batch file with:
pushd %~dp0
that set current directory folder containing batch file. in batch file, make sure paths relative current directory.
however, if batch file changes other directories in course of execution , still able refer batch's home folder's contents without knowing exact path, use same %~dp0
path file(s) want use. instance, filea
same folder batch file addressed as
"%~dp0filea"
note absence of \
before filea
. because %~dp0
includes trailing \
, entire thing evaluate correct path right. (although if put backslash, "%~dp0\filea"
, should work well, because windows disregards multiple consecutive backslashes when in middle of path.)
Comments
Post a Comment