在Windows批处理脚本中,通常我们可以找到if exist xxx
或if not exist xxx
。“如果存在”命令在Windows批处理脚本中如何工作?
这是否搜索指定的xxx
计算机中的所有文件,或任何特定的文件夹或路径?
在Windows批处理脚本中,通常我们可以找到if exist xxx
或if not exist xxx
。“如果存在”命令在Windows批处理脚本中如何工作?
这是否搜索指定的xxx
计算机中的所有文件,或任何特定的文件夹或路径?
如果您尚未指定文件夹,它将在当前文件夹中查找。 但你可以使用通配符。 例子:
if exist *.png echo There are images here
将输出,文本如果在当前文件夹中有与扩展名为.png
,或者你可以指定一个完整路径的任何文件,例如
if exist d:\temp\*.png echo There are images there
如果你希望它检查是否存在。然后让它执行一些事情。那么这就是你怎么做的:
if exist "D:randomstuff\random\ranodom\allala.jpg" goto anotherLabel
if not exist "D:randomstuff\random\ranodom\allala.jpg" goto addwrite
:anotherlabel
:addwrite
MKDIR D:randomstuff\random\ranodom\
echo this image doesn't exist> D:randomstuff\random\ranodom\allala.txt
or you can do this:
if exist randomfile.txt (
for /f %%A in (randomfile.txt) do set text=%%A
) else (
goto notexist.
基本上你在做什么。你插入路径到你想要检查的文件是否存在(带有文件名) ,然后你将它设置为执行一个动作来创建,添加,覆盖,复制,更改标签。等等。
谢谢你的回答! :) –
谢谢你的回答,所以它会搜索某个路径!我知道了! –