如何验证,如果一个文件在Windows .BAT文件是否存在? [英] How to verify if a file exists in a Windows .BAT file?

查看:155
本文介绍了如何验证,如果一个文件在Windows .BAT文件是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创造,这是否一个 .BAT 文件:

I have to create a .BAT file that does this:


  1. 如果 C:\\ myprogram \\同步\\ data.handler 存在,退出;

  2. 如果 C:\\ myprogram \\ HTML \\ data.sql 不存在,退出;

  3. C:\\ myprogram \\同步\\ 删除除(测试,<$ C $的所有文件和文件夹C> TEST3 和测试2

  4. 复制 C:\\ myprogram \\ HTML \\ data.sql C:\\ myprogram \\同步\\

  5. 通话与其他选项批处理文件 sync.bat myprogram.ini

  1. If C:\myprogram\sync\data.handler exists, exit;
  2. If C:\myprogram\html\data.sql does not exists, exit;
  3. In C:\myprogram\sync\ delete all files and folders except (test, test3 and test2)
  4. Copy C:\myprogram\html\data.sql to C:\myprogram\sync\
  5. 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.

推荐答案

您可以用是否存在来检查文件:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆