How to detect if folder is not empty (Windows Batc

2019-04-16 01:37发布

问题:

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