How to check for a blank file

G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.misc (More info?)

I am running a dos batch file and need to identify if a certain file is blank
/ 0 bytes.

If it is blank then I want to exit from the batch file etc

The version of dos successfully copies 0 byte files so i can't use that.

Can somebody help me and tell me is there any straightforward way of
performing this check?

Thanks in advance
Mike
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.misc (More info?)

Use FC to compare your file to a known empty file. Then check
the return code and exit if it is not equal or greater than one.

IF NOT ERRORLEVEL 1 EXIT

The return codes (ERRORLEVEL) for FC appear to be 0 for same, 1 for
different, 2 for file not exists.

Mike O'Neill wrote:
> I am running a dos batch file and need to identify if a certain file is blank
> / 0 bytes.
>
> If it is blank then I want to exit from the batch file etc
>
> The version of dos successfully copies 0 byte files so i can't use that.
>
> Can somebody help me and tell me is there any straightforward way of
> performing this check?
>
> Thanks in advance
> Mike
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.misc (More info?)

Thanks for your reply Frank.

The strange thing is that if i use FC the errorlevel is returned as 0 if the
files are the same

Then if i change one of the files and run again the difference is reported
by FC but the errorlevel is still returned as 0??

Is this some version issue....is there a solution or an alternative

thanks
Mike

"Frank Sandy" wrote:

> Use FC to compare your file to a known empty file. Then check
> the return code and exit if it is not equal or greater than one.
>
> IF NOT ERRORLEVEL 1 EXIT
>
> The return codes (ERRORLEVEL) for FC appear to be 0 for same, 1 for
> different, 2 for file not exists.
>
> Mike O'Neill wrote:
> > I am running a dos batch file and need to identify if a certain file is blank
> > / 0 bytes.
> >
> > If it is blank then I want to exit from the batch file etc
> >
> > The version of dos successfully copies 0 byte files so i can't use that.
> >
> > Can somebody help me and tell me is there any straightforward way of
> > performing this check?
> >
> > Thanks in advance
> > Mike
> >
>
 
G

Guest

Guest
Archived from groups: microsoft.public.windowsnt.misc (More info?)

The following batch file might work for you...
NOTE: different time/date output options might cause this not to work as
expected.
It expects dir to give the filesize as the 4th token and filename to be the
5th token.

REM ----- START OF ISEMPTY.BAT -----
@echo off
setlocal
set FN=%1
if not exist %FN% goto :END
for /f "tokens=1-5" %%a in ('dir %FN%') do call :CHECKFILE %%a %%b %%c %%d
%%e
goto :END
:CHECKFILE
if not {%5}=={%FN%} goto :EOF
if {%4}=={0} ( echo File is empty. ) else ( echo File is NOT empty. )
goto :EOF
:END
REM ----- END OF ISEMPTY.BAT -----

--
MikeVa [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--
Please do not send e-mail directly to this alias.
This alias is for newsgroup purposes only.
--
"Mike O'Neill" <Mike O'Neill@discussions.microsoft.com> wrote in message
news:7A1BD277-F85D-4B4B-8DA2-3DF2A492DBD2@microsoft.com...
> I am running a dos batch file and need to identify if a certain file is
blank
> / 0 bytes.
>
> If it is blank then I want to exit from the batch file etc
>
> The version of dos successfully copies 0 byte files so i can't use that.
>
> Can somebody help me and tell me is there any straightforward way of
> performing this check?
>
> Thanks in advance
> Mike
>