delete files with a 0kb size automatically

Posted on 2006-06-30
Last Modified: 2009-07-29
I'm looking for a Windows XP solution.  I'd like to be able to write a script or a batch file to allow me to create a file that will look for and delete files in a specified location with a file size of 0kb.  I plan to use task scheduler to run it on a regular basis.  A nice side benefit would be the ability to create a text log of how many files were deleted and the date and time they were deleted.  Any thoughts?
Question by:kevrut
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
  • 4
  • 2

Expert Comment

ID: 17019040
Post in the Visual Basic Area and someone will happily write you a vb script...
LVL 30

Expert Comment

ID: 17019275
xxcopy can do easily:

Expert Comment

ID: 17019771
NOPE... it can "not copy" files with a 0kb size but it wont delete them...
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

Dark_King earned 250 total points
ID: 17021228
Yes xxcopy shold do the jobb.

xxcopy c:\mydir\  /rsy /sz:0 /pd0

If you want to retain c:\mydir even if it becomes empty, add /ed
(otherwise, the directory will be removed also).  To include
subdirectory, add /s.


Expert Comment

ID: 17021504
invalid number of parameters when I run that...

Expert Comment

ID: 17021513
Nvm ignore my last post...  Good Find
LVL 30

Expert Comment

ID: 17021535
I almost have a dos script ready, been working couple hours on it...
LVL 30

Assisted Solution

callrs earned 250 total points
ID: 17022228
@echo off
:: zero.cmd: Produce delete commands & log for all zero-length files
:: By Ravinder Singh ('wiz' @ quickmacros forum) 2006-06-30
:: Arguments:
:; %1 - batch file to hold the delete commands to be run later
:: %2 - logfile to timestamp and log to
:; %3 - optional path
:: %4 - set to /r to recurse thru all folders below the path
::    - can be used as the third argument if arg#3 is ommited
:: Usage example:
::     zero.cmd zero0.bat zero.log c:\Temp /r
::  This - deletes all zero-length files in c:\Temp & under
::       - writes all del commandds to zero0.bat
::       - creates a dated log of all such files to zero.log
:: Save this script as c:\windows\zero.cmd (into a %path% folder)
::                  & then you can run it from any folder
set batfile=%1&set logfile=%2& set mypath=%3&set recurse=%4&set delcount=0
if %batfile%.==. goto :USAGE
if %logfile%.==. goto :USAGE
if exist %batfile% set /p deleteit=Delete %batfile%? (y/n)
if %deleteit%.==y. del %batfile%&echo.

echo. >> %logfile%
echo. >> %logfile%
echo "------ Zero length files delete report -------- %date% %time%" >> %logfile%

:: add trailing '\' to path
set pathend=%mypath:~-1%
if not %mypath%.==/r. if not %pathend%.==\. if not %mypath%.==. set mypath=%mypath%\

:: 3rd argument is '/r' instead of path?
if %mypath%.==/r. set recurse=%mypath%&set %mypath%=

:: Get full path of each file
if not %mypath%%recurse%.==%mypath%/r. (echo !!!&for %%a in (%mypath%*.*) do call :tokenize %%a
) else (echo ***&for /r %mypath%  %%a in (*.*) do call :tokenize %%a )
if not %delcount%.==0. (
type %batfile%&echo.
echo To execute the above %delcount% commands, type: %batfile%
echo Or to edit the above commands, type:     notepad %batfile%
if %delcount%==0 echo No zero-size files found
goto :eof

:: Get directory listing of a single file to tokenize the info
set File=%1
for /f "usebackq tokens=1,2,3,4,5,*" %%a in (`dir /a-d /-c "%File%"`) do call :deletezero %%a %%b %%c %%d %%e %%f
goto :eof

:: Write out delete command for zero-length file
if %4.==0. echo %file% >> %logfile% &echo del "%file%" >> %batfile%&set /a delcount+=1
goto :eof

echo. Usage:
echo  %~nx0 batfile logfile [path] [/r]&echo.
:: Like what you see? Care for the environment that fed me  : )

Expert Comment

ID: 17064535"zero+byte"+OR+"zero+length"+file
LVL 30

Expert Comment

ID: 17258937
Hours spent on a MS-DOS script that's been tested to work. So why the delete recommendation?

Both the XXCOPY (callrs & Dark_King) and the MS-DOS (callrs) scripts work...

[Curious as to why you mostly recommend "Delete"...]
LVL 30

Expert Comment

ID: 17259082
If I wasn't here to reply, the topic may have got deleted, as another one of my better responses got deleted last month http:Q_21856213.html. And one even got deleted without a warning http:Q_21890335.html; I"m thirsting to get at least a copy of that back...both are mentioned in my last query at Support.

You are at Genius level in XP. This case is about as cut & dry, black and white, as can get . The question asked is a do-able task, and any Windows geek should know about xxcopy & basic MS-DOS commands. If this topic doesn't demonstrate " In some cases it is possible to be almost certain that at least one reply made by the experts will solve the problem. ", then it's kind of disheartening for future...

But thanks for your great reply  : )  Appreciated.
LVL 30

Expert Comment

ID: 17331933
~~~ Well-thought-out solved posts told to be deleted too? ~~~   Windows XP: All programs "lock up" when selecting file/open (or save)

In sconnell's final comment before the delete recommendation,  on the second of only 3 lines, is: "After renaming that file, running a registry clean up, and finally rebooting. All is well in my world."

So did that get overlooked? How can we expect fairness when an obvious and valuable PAQ/refund is mis-stated as a delete? Sconnell thanked for my words in his absence.

It's hard to keep an optimistic outlook with this going on not only here & there but in delete recommendations by another admin whom I've seen even callandor get miffed at for a solved post recommended for delete...(and I'd find those posts, but it took ages just to manually locate the above link due to a defunct EE search feature that should be top priority but that won't even find my own id).

With the volume of EE mail now, it would only take a day off of working at EE before the mail piles up so much that I can't timely look at let alone answer all abandon notices. But when I do, even mod's thank me for my analysis, such as at http:Q_21930433.html

Hoping for better scanning/review of posts by admins; for the best.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Remaining XP devices from the environment. 12 78
Creating an XP virtual machine 38 180
Backup Windows XP system 9 141
A question on Active Directory LDS 4 26
Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…

733 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