This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
76} How do I create an empty file? How can I detect the empty files?
Creating an empty file:
if not exist empty.txt copy nul empty.txt
or
(which also works in Windows 10)
set /p=""<nul>empty.txt
Detecting empty files in a folder:
@echo off & setlocal enableextensions
for %%f in ("C:\_D\TEST\*.*") do (
if %%~zf EQU
0 echo %%~tf %%~zf "%%~ff"
)
endlocal & goto :EOF
The output could be e.g.
C:\_D\TEST>cmdfaq
09.06.2008 16:26 0 "C:\_D\TEST\empty.txt"
And throughout an entire drive
@echo off & setlocal enableextensions
for /f "tokens=*" %%f in ('dir /b/s/a-d "d:\*.*"') do (
if %%~zf EQU 0 echo %%~tf %%~zf %%~ff
)
endlocal & goto :EOF
Of course one could easily test for any particular size or range of
sizes. For example, are there files that are at least a megabyte in size?
@echo off & setlocal enableextensions
for /f "tokens=*" %%f in ('dir /b/s/a-d "c:\*.*"') do (
if %%~zf GEQ 1048576 echo %%~tf %%~zf %%~ff)
endlocal & goto :EOF
Finding empty
folders is covered in
item #57.