First: DO NOT use path
as a variable name. %path%
is a system variable that tells Windows where to find it's executables. Don't mess with it unless you know exactly what you do. Choose another name instead.
Second: your set
syntax defines a variable %path %
, and it's value starts with <space>"<space>C:...
. And the correct path delimiter is a backslash, not a slash. Best, use this syntax: set "mypath=%cd%..file.txt"
%cd%
is the "current working directory", which may or may not be identical with the "folder where the batch file is stored"
Third: the "folder, where your batch file is", is referenced as %~dp0
, so your desired file should be "%~dp0..file.txt"
, where %~dp0
= "folder, where the batch file is stored", ..
= "one folder up" and file.txt
= "your desired file" (this is called a "relative path").
the "Folder where file.txt
is stored, is just "%~dp0.."
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…