2016-12-30 37 views
1

如何才能检查文件夹是否缺少特定文件?我认为这将是if not exist X (execute Y)和路径名称的组合,但我还没有能够提出任何解决方案。CMD:检查特定文件夹中是否缺少特定文件

if /?

EXIST filename  Specifies a true condition if the specified filename exists. 

不知道在那里我会放文件夹的路径。

基本上我问的是我将如何Check if any type of files exist in a directory using BATCH script,但只在特定文件夹中的特定文件名? (然后在前面放置一个not

谢谢您提前。

回答

2

要安全检查的文件时,使用此(基于dir命令和redirection):

> nul 2>&1 dir /A:-D "D:\path\to\folder\file.ext" || echo File is missing! 

要检查的文件夹,你可以这样做:

> nul 2>&1 dir /A:D "D:\path\to\folder" || echo Folder is missing! 

为了完整起见:

要检查文件夹,请追加一个尾部\的路径,像

if not exist "D:\path\to\folder\" echo Folder is missing! 

要检查该文件夹中的特定文件,以下是不安全的...:

if not exist "D:\path\to\folder\file.ext" echo File is missing! 

...,因为这会not匹配的文件夹也叫file.ext

1
if not exist "d:\path to\filename.ext" (dothis) 

如果我正确理解你的目的。

相关问题