I have a Windows 2000 server which has a directory quickly accumulating log files. At this point there are over 100,000 of them in there, and deleting them via Windows Explorer is tedious at best. Each time I select a group of files, say about 100 or so, and delete them, the machine has to reindex the folder and its taking 20-30 mintes EACH TIME. The catch is that I can’t delete them all, only the files older than 2 months. Is there an easier way to do this?
Can you make a blank copy of the directory, and then just delete the entire old one in one go ?
Just thinking out loud here…
Well… off the top of my head, sort them by date. Scroll down (or up, depending on the direction) until you see the cutoff point you want. Click once on the first file you want to delete to select it. Then scroll to the end of the folder and while pressing shift select the last file to delete. Every file between the two should be selected, then right click, select delete while holding shift, and AAWWAAYY THEY GO!
Sorting by date takes about 20 minutes or more, selecting 100,000 files to delete at once will almost certainly crash the machine. I was hoping there is a good replacement for explorer I could use designed to deltee large quantities of files quickly.
Achilles, I can’t do that because I am only able to delete files older than 2 months in there.
I’d try doing it with a command line shell instead of the explorer, and specify files to remove with wildcards. Presumably, since they are log files, there’s a date somewhere in them, and you can specify patterns which match large chunks of them.
If you have a PC running an old version of Windows, copy winfile.exe off it and use that.
As it doesn’t support long file names it is much quicker dealing with folders containing hundreds of files.
Not included with Win2k though worse luck.
If you do programming in pretty much any language, it would be simple to create a script to do this for you. A script might take a while to iterate or work on a directory with this many files, but it’s typically a lot faster than Explorer, and you could let it run unattended. I write a lot of admin scripts to loop the files in a directory and copy certain ones to another location (e.g. create a new backup directory with a timestamp name and copy certain files to it based on some filename mask), zip or tar the files, delete the originals, etc. You could build the script to look for files with creation dates or filenames indicating a certain age and clean the directory based on a calculated, input, or hard-coded time period. Almost any language will provide the tools for doing this, and on Win2K it would be particularly simple using VBScript or Perl.
In general, if you find yourself doing the same thing over and over, you should replace that function with code. This is especially true if the thing you do repetitively is annoying or time consuming. If you don’t do programming, this would be an excellent introduction because the requirements for this script are narrow and well defined. You could probably teach yourself enough VBScript or Perl to make this work, and then you’d not only have a script to make your life easier, but the ability to write more scripts for other tasks.
As far as I can tell the del command (run from the command line) does not have a parameter to specify dates, and I need to keep the last two months and delete the rest.
I like the scripting idea, but I am a complete novice there and learning it well enough to do this would take me more time than simply waiting for the directory to refresh each time.
I had an idea which seemed to work ok. I searched by date in that directory and excluded the most recent stuff. Selected all the found files, deleted (took a good 30 minutes), and presto!, no more files. Thanks for all the suggestions guys, much appreciated.
If you can find/purchase unix-like tools for your windows box, you can accomplish this with a single command from a shell in the log directory:
find . -mtime +20 -exec rm “{}” “;”
removes all files in the current directory (.) that haven’t been modified (mtime) for 20 (+20) days.
-lv
Sounds like you solved your problem anyway, but I didn’t mean that I expected you to specify a date parameter to del. I meant that the log files probably had some pattern in them that you could use with file wildcarding, ie. “del log*2002.log”, and remove bunches of them at a time by matching the date that was probably in the file name.
I will admit that I seldom use the Windows command shell, and I don’t know how it handles extremely large pattern matches. I have the MKS toolkit installed on any windows box I use, and use its shell.
It is well worth getting a UNIX-like toolkit for use on a Windows environment. Then follow LordVor’s instructions. MKS is very good - unfortunately it is not free. At one point the Cygnus utilities were free - I don’t know if that’s still the case.
cygwin baby www.cygwin.com
You should be able to just install the default cygwin, run it, and enter LordVar’s command above. It’s enormous in capability beyond what you need, but it’ll do the trick. Cygwin is basically unix ported to your pc (sort of).