Solved

How to detect zero byte files in Windows

Posted on 2011-09-29
6
1,084 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:epmmis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 66

Accepted Solution

by:
johnb6767 earned 125 total points
ID: 36818149
dir C:\Folder\test.bmp | find " 1 File(s)              0 bytes" && echo File is ZERO Bytes......

Simply returns "File is ZERO Bytes......"

Or set a variable etc.....

Keep the spacing as is... I'm sure there is a more graceful method than this batch...........


0
 
LVL 16

Assisted Solution

by:AlexPace
AlexPace earned 125 total points
ID: 36818208
Another option is to use a scriptable FTP server.  For example, if you used Robo-FTP Server you write a short script that is triggered by the UploadComplete event.  The script would check the size of the uploaded file and delete it if the length is 0 bytes.
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 125 total points
ID: 36818485
This would work in VBScript.

Regards,

Rob

strFolder = "C:\Files"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strFolder).Files
   If objFile.Size = 0 Then objFile.Delete True
Next

Open in new window

0
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 
LVL 66

Expert Comment

by:johnb6767
ID: 36818543
Yeah, prettier indeed...
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 125 total points
ID: 36818906
This DOS command scans the current folder for zero-length files and deletes them.

for %i in (*) do @if "%~zi"=="0" del "%i"

Open in new window


Note that if you use this in a batch file, you need to double-up the percent signs.
0
 

Author Closing Comment

by:epmmis
ID: 36912464
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.
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question