你好,我想写一个批处理文件来检查给定文件夹中是否有任何类型的文件.
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" )如果我知道文件扩展名(例如带有以下内容的 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)更多推荐
使用 BATCH 脚本检查目录中是否存在任何类型的文件
发布评论