Use DIR command in Windows to find all files with 0 bit size?

N

numismatic

Something like dir /s C:\*.* /O:S, but only return those files with a
0-bit filesize. A way to write it to txt file would be nice too
( >txt.txt???)
 
T

Tom Lavedas

Something like dir /s C:\*.* /O:S, but only return those files with a
0-bit filesize. A way to write it to txt file would be nice too
( >txt.txt???)

Try this (presuming WinNT/2K/2003/XP[Vista?]), but beware it could
take quite a while to scan a whole drive ...


(@for /r "C:\" %a in (*.*) do if %~za==0 echo %~fa) > out.txt

If you put it in a batch file, double up the percent signs.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
B

billious

Tom Lavedas said:
Something like dir /s C:\*.* /O:S, but only return those files with a
0-bit filesize. A way to write it to txt file would be nice too
( >txt.txt???)

Try this (presuming WinNT/2K/2003/XP[Vista?]), but beware it could
take quite a while to scan a whole drive ...


(@for /r "C:\" %a in (*.*) do if %~za==0 echo %~fa) > out.txt

If you put it in a batch file, double up the percent signs.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Didn't work properly for me under XP - reported each FOR iteration into the
file. ~z modifier is not available under NT, not sure about 2K.

From the prompt,

@echo off&(@for /r "C:\" %a in (*.*) do if %~za==0 >>out.txt echo %a&echo on

Seemed to work fine though - but you'd have to delete out.txt first as the
output is APPENDED to the file

This solution developed using XP

----- batch begins -------
[1]@echo off
[2]del out.txt 2>nul
[3]for /r "C:\106x" %%a in (*.*) do if %%~za==0 >>out.txt echo %%a
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

C:\106x... is my test directory - simply replace with YOUR start-directory's
name.
 
N

numismatic

Try this (presuming WinNT/2K/2003/XP[Vista?]), but beware it could
take quite a while to scan a whole drive ...
(@for /r "C:\" %a in (*.*) do if %~za==0 echo %~fa) > out.txt
If you put it in a batch file, double up the percent signs.

Didn't work properly for me under XP - reported each FOR iteration into the
file. ~z modifier is not available under NT, not sure about 2K.

From the prompt,

@echo off&(@for /r "C:\" %a in (*.*) do if %~za==0 >>out.txt echo %a&echo on

Seemed to work fine though - but you'd have to delete out.txt first as the
output is APPENDED to the file

This solution developed using XP

----- batch begins -------
[1]@echo off
[2]del out.txt 2>nul
[3]for /r "C:\106x" %%a in (*.*) do if %%~za==0 >>out.txt echo %%a
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

C:\106x... is my test directory - simply replace with YOUR start-directory's
name.

Thanks to Tom and billious...I couldn't quite get Tom's code to work
either, but I'm sure it's due to my lack of knowledge and not an error
in the code.
billious, your batch file worked perfectly for me, thank you! I can't
believe it's so difficult to retrieve a listing of 0 length files from
the command line without 3rd party sw.
Thanks again!
 
T

Tom Lavedas

news:605e0006-2d60-4d21-9a5b-ec39cc91622d@p43g2000hsc.googlegroups.com...
Something like dir /s C:\*.* /O:S, but only return those files with a
0-bit filesize. A way to write it to txt file would be nice too
( >txt.txt???)
Try this (presuming WinNT/2K/2003/XP[Vista?]), but beware it could
take quite a while to scan a whole drive ...
(@for /r "C:\" %a in (*.*) do if %~za==0 echo %~fa) > out.txt
If you put it in a batch file, double up the percent signs.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Didn't work properly for me under XP - reported each FOR iteration into the
file. ~z modifier is not available under NT, not sure about 2K.
From the prompt,
@echo off&(@for /r "C:\" %a in (*.*) do if %~za==0 >>out.txt echo %a&echo on
Seemed to work fine though - but you'd have to delete out.txt first as the
output is APPENDED to the file
This solution developed using XP
----- batch begins -------
[1]@echo off
[2]del out.txt 2>nul
[3]for /r "C:\106x" %%a in (*.*) do if %%~za==0 >>out.txt echo %%a
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
C:\106x... is my test directory - simply replace with YOUR start-directory's
name.

Thanks to Tom and billious...I couldn't quite get Tom's code to work
either, but I'm sure it's due to my lack of knowledge and not an error
in the code.
billious, your batch file worked perfectly for me, thank you! I can't
believe it's so difficult to retrieve a listing of 0 length files from
the command line without 3rd party sw.
Thanks again!

OK. I ran my test at the command console with ECHO OFF and missed the
problem. I also didn't realize the backward compatibility issue.

A slightly shorter solution for the command prompt than billous'
is ...

(@for /r "C:\" %a in (*.*) do @if %~za==0 @echo %~fa) > %temp%\out.txt

There is also a small problem with the redirection, if the OUT.TXT
file is in the root folder of the search - it may (under very specific
conditions) show up in the list of Zero-byte files. So, I propose
forcing it to the system's TEMP folder as a place that is not likely
to be searched first.

Actually, even in the %TEMP% folder, if there are no zero-byte files
or none found by the time the TEMP folder is searched, the OUT.TXT
file may well show up in the list (always as the first item in the
list) - Again, nothing's perfect. It could be solved, but I doubt
it's worth the effort.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
F

foxidrive

Actually, even in the %TEMP% folder, if there are no zero-byte files
or none found by the time the TEMP folder is searched, the OUT.TXT
file may well show up in the list (always as the first item in the
list) - Again, nothing's perfect. It could be solved, but I doubt
it's worth the effort.

for /f creates it's list prior to creating the output file so will solve
that issue. As an aside, I avoid using for /r as it is unreliable in
certain circumstances, and for /f can always replace it.

@echo off
for /f "delims=" %%a in (
'dir c:\ /s /b /a-d'
) do if %%~za==0 echo %%~fa > "out.txt"
 
B

billious

foxidrive said:
for /f creates it's list prior to creating the output file so will solve
that issue. As an aside, I avoid using for /r as it is unreliable in
certain circumstances, and for /f can always replace it.

@echo off
for /f "delims=" %%a in (
'dir c:\ /s /b /a-d'
) do if %%~za==0 echo %%~fa > "out.txt"

Leetle correction:

">>" not ">" otherwise only the last zero-length filename will be placed in
out.txt.

Again, you'd probably need to delete any existing "out.txt" before
executing the FOR
 
T

Tom Lavedas

Leetle correction:

">>" not ">" otherwise only the last zero-length filename will be placed in
out.txt.

Again, you'd probably need to delete any existing "out.txt" before
executing the FOR

That's why I used the parens around the FOR (to eliminate the need to
delete the OUT file first. Therefore, ...

@echo off
(for /f "delims=" %%a in ('dir c:\ /s /b /a-d'
) do if %%~za==0 echo %%~fa) > "out.txt"

Though, I still like my one-liner.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
F

foxidrive

That's why I used the parens around the FOR (to eliminate the need to
delete the OUT file first. Therefore, ...

Ahh, thanks for pointing that out. I hadn't realised...
 
B

Blue Fish

Hello:

It was quite useful for me. May I more information regrading the "~fa,
~za, ~???" command for reference?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top