Empty.cmd

CMD Batch script to show if a folder is empty.

This script will scan all files in the folder, which may be slow if there are thousands of files, but it does not recursively scan through all the subfolders, if a single subfolder is found, empty or not, that is taken as a signal that the parent folder is not empty.

@Echo off
Setlocal
if {%1}=={} set _empty=Syntax: %0 "" &goto :message

::Does folder exist
if not exist %1 (
  set _empty=No Such Folder
  goto :message
)

:: Is folder empty
set _TMP=
for /f "delims=" %%a in ('dir /a /b %1') do set _TMP=%%a

IF {%_TMP%}=={} (
  set _empty=Empty
) ELSE (
  set _empty=Not Empty
)

:message
echo:
Echo %_empty%
echo:
Endlocal & set _empty=%_empty%

“The difference between false memories and true ones is the same as for jewels: it is always the false ones that look the most real, the most brilliant” ~ Salvador DalĂ­

Related:

DELTREE - Delete a folder and all subfolders/files.
Delete only empty folders and log results.

RD - Remove (or Delete) a Directory.
IF command


 
Copyright © 1999-2021 SS64.com
Some rights reserved