Windows bat脚本:如何判断文件是否存在?

发布于 2024-11-26 10:21:24 字数 93 浏览 7 评论 0原文

伪代码:

if file exists:
do
    xxxx
done
else:
do
    xxxx
done

Pseudo code:

if file exists:
do
    xxxx
done
else:
do
    xxxx
done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

会傲 2024-12-03 10:21:24

您可以使用 exist

if exist somefile.dat echo It exists

根据“方言”,您可以使用 else 语句。然而,在最底层,一些相当丑陋的逻辑是有效的:

if exist somefile.dat goto fileexists
echo file does not exist
goto alldone

:fileexists
echo file exists

:alldone

You can use exist:

if exist somefile.dat echo It exists

Depending on the "dialect", you can use else statements. At the lowest level, though, some rather ugly logic like this works:

if exist somefile.dat goto fileexists
echo file does not exist
goto alldone

:fileexists
echo file exists

:alldone
染火枫林 2024-12-03 10:21:24

语法如下:

IF [NOT] EXIST filename 命令

如果文件不存在(而不是文件存在),您可以使用 [NOT] 选项来执行代码,但这可以作为 ELSE 语句来完成。标准 IF EXIST 语句。

IF EXIST stuff.txt (
  ECHO It exists
) ELSE (
  ECHO It doesn't exist
)

Syntax is as follows:

IF [NOT] EXIST filename command

You can use the [NOT] option to execute code if a file doesn't exist as opposed to if the file does exist, however this can be done as an ELSE staement in a standard IF EXIST statement.

IF EXIST stuff.txt (
  ECHO It exists
) ELSE (
  ECHO It doesn't exist
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文