Link to home
Start Free TrialLog in
Avatar of epmmis
epmmis

asked on

How to detect zero byte files in Windows

I need a method (vb script / batch file) to detect a zero byte text file with in a folder.  We using both XP and Windows 2003 machines to recieve many text files via ftp.  After the files are recieved they are processed by a mapping program.  When a zero byte file is processes by the mapping program the program fails.  

I need a script / batch file to detect the zero byte text files and then delete them.
ASKER CERTIFIED SOLUTION
Avatar of johnb6767
johnb6767
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, prettier indeed...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of epmmis
epmmis

ASKER

Thank AlexPace. We do use RoboFTP as our FTP client.  RoboFTP tech support provided this solution.

Are these zero byte files downloaded from a remote site or do they come from somewhere else?  If they come from the site then maybe it would be easier to use FTPGETFILE or GETSITEFILE to set the value of the %sitefilesize variable and then only download the files with more than 0 bytes.  If the files have a local or unknown source you could add a little loop at the bottom of your script that uses GETNEXTFILE to set the %nextfilesize variable and then get rid of the zero byte files.
If you use these commands in a loop that deletes or renames files you'll need to use GETREWIND or FTPGETREWIND after deleting or renaming a file.  This starts the loop over at the top so it is inefficient but shouln't cause any preceptable delay unless the folders you are processing contain hundreds of files.  The reason this is necessary is that, internally, these command keep track of which file they are processing by noting its ordinal position within the directory listing.  Deleting or renaming files changes the order of the directory listing so the command gets confused if, for example, the file that WAS the 3rd file is now the 4th file.
Here is an example of using GETFILE in a loop to delete local 0 byte files:
GETREWIND
:fetch_file_stats
GETFILE "*"
IFERROR= $ERROR_NO_FILE_FOUND GOTO no_more_files
IFNUM> %nextfilesize 0 GOTO fetch_file_stats
DELETE %nextfile
GETREWIND
GOTO fetch_file_stats
:no_more_files

The rest of the answers were good too.  So you all get points for the exceptional answers.