Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

delete files with a 0kb size automatically

Posted on 2006-06-30
16
Medium Priority
?
544 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
[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
  • 4
  • 2
16 Comments
 
LVL 9

Expert Comment

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

Expert Comment

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

Expert Comment

by:justchat_1
ID: 17019771
NOPE... it can "not copy" files with a 0kb size but it wont delete them...
0
Industry Leaders: 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!

 
LVL 6

Accepted Solution

by:
Dark_King earned 1000 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.


0
 
LVL 9

Expert Comment

by:justchat_1
ID: 17021504
invalid number of parameters when I run that...
0
 
LVL 9

Expert Comment

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

Expert Comment

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

Assisted Solution

by:callrs
callrs earned 1000 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
::
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
ID: 17064535
http://groups.google.com/groups?q=batch.nt++delete+"zero+byte"+OR+"zero+length"+file
0
 
LVL 30

Expert Comment

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

Expert Comment

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

Expert Comment

by:callrs
ID: 17331933
~~~ 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like 192.168.xxx.1, I've seen routers with default values of: 192.168.0.1, 192.168.1.1, 192.168.11.1, …
Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 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