问题
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