批处理文件创建

批处理文件创建

我在批处理文件代码中写了以下代码

if not exist "C:\Windows\Temp\web.config.hints.cancer.gov" (
 echo Error: "%TMP%\web.config.hints.cancer.gov" does not exist! )

pause
exit

但是,它并没有按要求运行。我收到以下消息

C:\Users\dod\Desktop>if not exist "C:\Windows\Temp\web.config.hints.cancer.gov"
(echo Error: "C:\Users\dod\AppData\Local\Temp\web.config.hints.cancer.gov" does
not exist!  )
Error: "C:\Users\dod\AppData\Local\Temp\web.config.hints.cancer.gov" does not ex
ist!

C:\Users\dod\Desktop>pause
Press any key to continue . . .

答案1

%TMP%%TEMP%都指向C:\Users\username\AppData\Local\Temp,而不是C:\Windows\Temp。您需要写下完整路径或手动将其放入变量中,如下所示:

SET folder="C:\Windows\Temp"

...your code...

echo Error: %folder%\web.config.hints.cancer.gov does not exist!

相关内容