使用 BATCH 脚本检查目录中是否存在任何类型的文件

编程入门 行业动态 更新时间:2024-10-27 08:40:24
本文介绍了使用 BATCH 脚本检查目录中是否存在任何类型的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我想写一个批处理文件来检查给定文件夹中是否有任何类型的文件.

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 脚本检查目录中是否存在任何类型的文件

本文发布于:2023-11-27 15:45:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否存在   脚本   类型   文件   目录中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!