3 回答
TA贡献1943条经验 获得超7个赞
您可以使用是否存在来检查文件:
IF EXIST "filename" (
REM Do one thing
) ELSE (
REM Do another thing
)
如果你不需要一个“其他”,你可以这样做:
set __myVariable=
IF EXIST "C:\folder with space\myfile.txt" set __myVariable=C:\folder with space\myfile.txt
IF EXIST "C:\some other folder with space\myfile.txt" set __myVariable=C:\some other folder with space\myfile.txt
set __myVariable=
下面是搜索文件或文件夹的工作示例:
REM setup
echo "some text" > filename
mkdir "foldername"
REM finds file
IF EXIST "filename" (
ECHO file filename exists
) ELSE (
ECHO file filename does not exist
)
REM does not find file
IF EXIST "filename2.txt" (
ECHO file filename2.txt exists
) ELSE (
ECHO file filename2.txt does not exist
)
REM folders must have a trailing backslash
REM finds folder
IF EXIST "foldername\" (
ECHO folder foldername exists
) ELSE (
ECHO folder foldername does not exist
)
REM does not find folder
IF EXIST "filename\" (
ECHO folder filename exists
) ELSE (
ECHO folder filename does not exist
)
TA贡献1817条经验 获得超6个赞
输入IF /?要获得有关的帮助,它清楚地说明了如何使用IF EXIST。
要删除除某些文件夹以外的完整树,请参阅以下问题的答案:Windows批处理脚本删除除一个文件夹外的所有内容
最后复制只是意味着可以调用COPY并调用另一个bat文件,如下所示:
MYOTHERBATFILE.BAT sync.bat myprogram.ini
- 3 回答
- 0 关注
- 566 浏览
添加回答
举报