How to find a zero byte file?

  • Thread starter Thread starter branigan
  • Start date Start date
Hello, branigan:
On Wed, 17 Nov 2004 14:57:57 -0500: you wrote...

b> Could anyone tell me how to find a zero byte file?
b>

Remove the /s switch if you don't want it to recurse through the subdirs.

@echo off
for /f "tokens=*" %%c in ('dir /b /a-d /s "%1"') do (
if %%~zc equ 0 echo %%c %%~zc
)

C:\Users\sadowski [(firecat) 16:47, Wed 11/17/2004] zerobyte.cmd .
c:\users\sadowski\.lastlog 0
c:\users\sadowski\graph\msgraph-1.34\changes 0
c:\users\sadowski\scripts\cmdscripts\hclink.out 0

Regards, Paul R. Sadowski [MVP].
 
branigan said:
Could anyone tell me how to find a zero byte file?
If you create one, you don't have to search ;-)

copy NUL ZeroByte

But here is my one, similar to Paul's. In the hope it is faster I get
the folder list first, iterating through each folder and aborting if
size not zero.

::FindZeroByte.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
call :sub %1
For /F "delims=" %%A in ('dir /B/S/AD %1 2^>NUL') do call :sub "%%~fA"
goto :eof
:sub
for /F "delims=" %%B in ('dir /B/OS/A-D "%~1\*" 2^>NUL'
) do if %%~zB. EQU 0. (echo %%~zB %%~fB) else (goto :eof)
::FindZeroByte.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::

A 3rd party app which works from the cmd line is fi.exe from Frank P.
Westlake. Hosted now by Ted Davis at http://gearbox.maem.umr.edu/fwu/

fi /S /B /Z"="0 *

HTH
 
Back
Top