JSI Tip 9350. Another way to test if a folder is empty.

In tip 6415 » How can a batch script test if a folder is empty, or contains folders, files, or both folders and files, we scripted FFExist.bat.

If you simply need to determine if a folder is empty or not, you can use fMT.bat.

The syntax for using fMT.bat is:

fMT Folder YesNoVar

Where Folder is the path to the folder you wish to test, and YesNoVar is a call directed environment variable that will be set Y if the Folder is empty, N is the Folder is NOT empty, or X if the Folder does not exist.

fMT.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: fMT Folder YesNoVar&goto :EOF
if not exist %1 set %2=X&goto :EOF
dir %1 /b | find /v "tHiS sHoUdn'T bE fOuNd" >nul && (set %2=N) || (set %2=Y)

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.