windows - 即使为真,批处理文件也会忽略 If 语句
问题描述
在某个批处理文件的某个地方,我有一段代码可以检查目录是否存在。如果没有,请询问用户该怎么做。现在奇怪的是,当目录存在时,我仍然会收到“你想创建目录吗?”的问题。在 if 语句中。
我在这里想念什么?
cls
@echo off
SET PanterPath="W:\Windows\Panther\"
if NOT exist %PanterPath% (
echo Directory %PanterPath% not found! Cannot copy and apply unattend file.
SET /P var=Do you want to create the directory? (Y/N)
if /I "%var%" EQU "Y" (
echo Creating directory %PanterPath% ...
mkdir %PanterPath%
) else (
echo Directory %PanterPath% not created so script cannot continue. The image deployment failed!
pause
exit
)
)
pause
pause
编辑当我向If Exists
then 中添加 else 语句时,输出为:
Directory "W:\Windows\Panther" found
Directory "W:\Windows\Panther" not created so script cannot continue. The image
deployment failed
Press the any key...
代码:
SET PanterPath="W:\Windows\Panther"
If Exist "%PanterPath%\" (
echo Directory %PanterPath% found!
) else (
echo Directory %PanterPath% not found! Cannot copy and apply unattend file.
SET /P var=Do you want to create the directory? (Y/N)
if /I "%var%" == "Y" (
echo Creating directory %PanterPath% ...
mkdir %PanterPath%
) else (
echo Directory %PanterPath% not created so script cannot continue. The image deployment failed!
pause
exit
)
)
pause
pause
解决方案
推荐阅读
- python - 匹配 HTML 文本末尾的空段落
- python - ImportError:尝试运行 Pythontex 时没有名为 pygments.styles 的模块
- r - 使用 R 中给定的一组关键字计算单词的数量
- c++ - Visual Studio 2019 中的 C++ 单元测试
- pandas - Sklearn datasets 默认数据结构是pandas还是numPy?
- c - GCC ASM 从 C 将 AH 寄存器设置为 1h
- asp.net - 如何在 .Net Core MVC 中发布
- node.js - 等待异步调用完成,以便我可以使用结果,它不起作用?
- javascript - 停止 FORM 提交并弹出对话框
- sql - 在数字序列中查找错过的最大值和最小值