检查是否有任何类型的文件使用批处理脚本在目录中 [英] Check if any type of files exist in a directory using BATCH script
问题描述
您好,我希望写一个批处理文件来检查,看看是否有一个给定的文件夹中的任何类型的任何文件。
Hello I'm looking to write a batch file to check to see if there are any files of any type inside a given folder.
到目前为止,我已经试过以下
So far I've tried the following
if EXIST FOLDERNAME\\*.* ( echo Files Exist ) ELSE ( echo "Empty" )
我可以得到它,如果我知道文件扩展工作,如与follwing一个txt文件
I can get it to work if I know the file extension such as a txt file with the follwing
if EXIST FOLDERNAME\\*.txt ( echo Files Exist ) ELSE ( echo "Empty" )
感谢您的帮助。
推荐答案
要检查,如果一个文件夹至少包含一个文件
To check if a folder contains at least one file
>nul 2>nul dir /a-d "folderName\*" && (echo Files exist) || (echo No file found)
要检查是否有文件夹或任何其后代至少包含一个文件
To check if a folder or any of its descendents contain at least one file
>nul 2>nul dir /a-d /s "folderName\*" && (echo Files exist) || (echo No file found)
要检查一个文件夹中包含至少一个文件或文件夹。
的注意除了 / A
选项来启用隐藏和系统文件/文件夹中发现的。的
To check if a folder contains at least one file or folder.
Note addition of /a
option to enable finding of hidden and system files/folders.
dir /b /a "folderName\*" | >nul findstr "^" && (echo Files and/or Folders exist) || (echo No File or Folder found)
要检查,如果一个文件夹至少包含一个文件夹
To check if a folder contains at least one folder
dir /b /ad "folderName\*" | >nul findstr "^" && (echo Folders exist) || (echo No folder found)
这篇关于检查是否有任何类型的文件使用批处理脚本在目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!