Solved

delete files with a 0kb size automatically

Posted on 2006-06-30
16
536 Views
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?
0
Comment
Question by:kevrut
  • 6
  • 4
  • 2
16 Comments
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
Post in the Visual Basic Area and someone will happily write you a vb script...
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
xxcopy can do easily: http://www.xxcopy.com/xxcopy12.htm
0
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
NOPE... it can "not copy" files with a 0kb size but it wont delete them...
0
 
LVL 6

Accepted Solution

by:
Dark_King earned 250 total points
Comment Utility
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.


0
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
invalid number of parameters when I run that...
0
 
LVL 9

Expert Comment

by:justchat_1
Comment Utility
Nvm ignore my last post...  Good Find
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Expert Comment

by:callrs
Comment Utility
I almost have a dos script ready, been working couple hours on it...
0
 
LVL 30

Assisted Solution

by:callrs
callrs earned 250 total points
Comment Utility
@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
::
setlocal
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 )
:done
echo.
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

:tokenize
:: 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

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


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

Expert Comment

by:Dark_King
Comment Utility
http://groups.google.com/groups?q=batch.nt++delete+"zero+byte"+OR+"zero+length"+file
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
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"...]
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
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.
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
~~~ Well-thought-out solved posts told to be deleted too? ~~~
http://www.experts-exchange.com/Q_21902950.html   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.

-R.S.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now