如何检测文件夹是否为空(Windows批处理文件)? [英] How to detect if folder is not empty (Windows Batch File)?

查看:838
本文介绍了如何检测文件夹是否为空(Windows批处理文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一个简单的批处理文件,该文件与Windows 7中的命令处理器兼容,如何检测文件夹是否包含任何内容(意味着一个或多个文件或子文件夹,即不为空)?

Using a simple batch file, compatible with the command processor in Windows 7, how can one detect if a folder has any contents (meaning one or more files or subfolders, i.e. not empty)?

我尝试过:

IF EXIST C:\FOLDERNAME\* GOTO ROUTINE

但这总是返回TRUE并因此转到ROUTINE.

But this always returns TRUE and thus goes to ROUTINE.

这怎么完成?

推荐答案

dir /A /B /S "C:\FOLDERNAME" | findstr /L ".">NUL && GOTO ROUTINE

/S也可以查看子目录 /R未提供我期望的结果,因此尝试使用/L

/S to look also into subdirectories /R was not giving the results I expected, so tried with /L

(仅适用于名称中没有带圆点的文件夹....)

(only works if there are not folders with dots in their name....)

这篇关于如何检测文件夹是否为空(Windows批处理文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆