How to detect if folder is not empty (Windows Batch File)?

心已入冬 提交于 2019-12-21 22:45:53

问题


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)?

I tried:

IF EXIST C:\FOLDERNAME\* GOTO ROUTINE

But this always returns TRUE and thus goes to ROUTINE.

How can this be accomplished?


回答1:


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

/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....)



来源:https://stackoverflow.com/questions/43408860/how-to-detect-if-folder-is-not-empty-windows-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!