find 0 bytes file in a folder

M

Mak

Hi,

In part of a batch, I need to evaluate if two (maybe three) text files with
known names exist in the current folder and if they are, check they are not
empty.
The first part is easy, but I got stuck on the second.

Ideally, I'd like batch to stop checking and do something as soon as the
first 0 bytes file found, but this isn't critical, there won't be many files
in this folder, I can live with evaluating every single file.

I have isolated second part into this:
@echo off
setlocal
set crap=
for %%i in (*) do (
set crap=%%~zi
call :check
)
goto end

:check
if %crap% EQU 0 (
echo found
pause
)
goto:eof

:end
endlocal & goto:eof

The above works, but I have the feelings it can be done differently, better.
For some reason I'm in mental block with this task, hence asking for help.
Oh, and I'd like to avoid using enabledelayedexpansion (if possible),
external files and utilities. OSes this batch needs to work on: W2k, XP and
W2k3.
 
B

billious

Mak said:
Hi,

In part of a batch, I need to evaluate if two (maybe three) text files
with known names exist in the current folder and if they are, check they
are not empty.
The first part is easy, but I got stuck on the second.

Ideally, I'd like batch to stop checking and do something as soon as the
first 0 bytes file found, but this isn't critical, there won't be many
files in this folder, I can live with evaluating every single file.

I have isolated second part into this:
@echo off
setlocal
set crap=
for %%i in (*) do (
set crap=%%~zi
call :check
)
goto end

:check
if %crap% EQU 0 (
echo found
pause
)
goto:eof

:end
endlocal & goto:eof

The above works, but I have the feelings it can be done differently,
better. For some reason I'm in mental block with this task, hence asking
for help. Oh, and I'd like to avoid using enabledelayedexpansion (if
possible), external files and utilities. OSes this batch needs to work on:
W2k, XP and W2k3.

----- batch begins -------
[1]@echo off
[2]for %%i in (*) do if %%~zi==0 set yzb=%%i&goto found
[3]echo no zero-byte files found
[4]goto :eof
[5]:found
[6]echo %yzb% is a zero-byte file
------ 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

The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof

alt.msdos.batch.nt for NT+ batch techniques.....
 
M

Mak

billious said:
----- batch begins -------
[1]@echo off
[2]for %%i in (*) do if %%~zi==0 set yzb=%%i&goto found
[3]echo no zero-byte files found
[4]goto :eof
[5]:found
[6]echo %yzb% is a zero-byte file
------ batch ends --------

This is good, thank you.
The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof

You've lost me here. Why are you saying this?
 
B

billious

Mak said:
billious said:
----- batch begins -------
[1]@echo off
[2]for %%i in (*) do if %%~zi==0 set yzb=%%i&goto found
[3]echo no zero-byte files found
[4]goto :eof
[5]:found
[6]echo %yzb% is a zero-byte file
------ batch ends --------

This is good, thank you.
The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof

You've lost me here. Why are you saying this?

I use a script to generate a reply skeleton, using my tested batchcode to
add the [number] to the text.

Since [4] contains ":eof", the batch detected it and spat out the
appropriate line. Comes of having too many complaints that "it doesn't work"
because the colon was omitted or "but you didn't put in the label 'eof.'"
Consequently, it's become SOP (at least in alt.msdos.batch.nt) to include
all the waffle. Bit like the obligatory warning on chocolate peanut bars
"Warning: contains peanuts."
 
M

Mak

billious said:
You've lost me here. Why are you saying this?

I use a script to generate a reply skeleton, using my tested batchcode to
add the [number] to the text.

Since [4] contains ":eof", the batch detected it and spat out the
appropriate line. Comes of having too many complaints that "it doesn't
work" because the colon was omitted or "but you didn't put in the label
'eof.'" Consequently, it's become SOP (at least in alt.msdos.batch.nt) to
include all the waffle. Bit like the obligatory warning on chocolate
peanut bars "Warning: contains peanuts."

oh, and I've even started to think I've made some trivial mistake in my
batch and you're pointing it out, note to self: use Occam's razor.
Thanks again.
 

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