Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Zero Byte Files  (Read 3936 times)

0 Members and 1 Guest are viewing this topic.

edi_guy

  • Guest
Zero Byte Files
« on: April 21, 2006, 08:15:59 PM »
Hi,

I have done some DOS batch programming in the past, but I have run into a situation where I could use some help.

How do tell if a file has 0 (zero) bytes.  I have a script that goes to an FTP site to bring in a file.  It creates a file even if there is nothing there, hense a file with zero bytes.

I want to be able to test for this and NOT copy it to a directory that other software is monitoring.  The software process it, but generates errors.  The users don't like errors.

I can do it in a *nix script, but I am at a loss to do it in DOS.

I seem to remember a batch file comparing an existing zero byte file to the new file and if it matched, then it was emtpy.

I can't find the reference and I can't find anything in my DOS manuals.

HELP.

Thanks to all.

DosItHelp



    Intermediate
    Re: Zero Byte Files
    « Reply #1 on: April 21, 2006, 09:36:30 PM »
    edi_guy!

    Is this what you want?

    set file=filename.txt
    for %%a in ("%file%") do set size=%%za
    if "%size%" NEQ "0" echo.DO THE COPY


    or

    set file=filename.txt
    dir "%file%"|find /i " 0 %file%">NUL&&echo.DO THE COPY


    I would prefer the first one.
    Check also http://dostips.cmdtips.com/DtCodeSnippets.php

    Hope this helps ;)
    « Last Edit: April 21, 2006, 09:36:43 PM by DosItHelp »