如何验证Windows .BAT文件中是否存在文件? [英] How to verify if a file exists in a Windows .BAT file?
本文介绍了如何验证Windows .BAT文件中是否存在文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建一个 .BAT
文件:
- 如果
C:\myprogram\sync\data.handler
存在,退出; - 如果
C :\myprogram\html\data.sql
不存在,退出; - 在
C:\myprogram \ sync\
删除所有文件和文件夹(test
,test3
和test2
) - 复制
C:\myprogram\html\data.sql
C:\myprogram\sync\
- 使用选项
sync.bat myprogram.ini
。
- If
C:\myprogram\sync\data.handler
exists, exit; - If
C:\myprogram\html\data.sql
does not exists, exit; - In
C:\myprogram\sync\
delete all files and folders except (test
,test3
andtest2
) - Copy
C:\myprogram\html\data.sql
toC:\myprogram\sync\
- Call other batch file with option
sync.bat myprogram.ini
.
如果是在Bash环境中,我很容易,不知道如何测试文件或文件夹是否存在以及是否为文件或文件夹。
If it was in the Bash environment it was easy for me, but I do not know how to test if a file or folder exists and if it is a file or folder.
推荐答案
可以使用IF EXIST检查文件:
You can use IF EXIST to check for a file:
IF EXIST "filename" (
REM Do one thing
) ELSE (
REM Do another thing
)
如果要查找驱动器或目录,请参见 http://support.microsoft.com/kb/65994 示例
If you want to look for a drive or directory, see http://support.microsoft.com/kb/65994 for examples
这篇关于如何验证Windows .BAT文件中是否存在文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文