# Lots 'o Files:  Delete?

**URL:** <https://boards.straightdope.com/t/lots-o-files-delete/192353>\
**Category:** Factual Questions\
**Created:** [August 1, 2003, 1:53pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353 "2003-08-01T13:53:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bongmaster](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bongmaster](https://boards.straightdope.com/u/Bongmaster)\
**Post date:** [August 1, 2003, 1:53pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/1 "2003-08-01T13:53:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Achilles](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@Achilles](https://boards.straightdope.com/u/Achilles)\
**Post date:** [August 1, 2003, 2:01pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/2 "2003-08-01T14:01:49Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Phage](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Phage](https://boards.straightdope.com/u/Phage)\
**Post date:** [August 1, 2003, 2:02pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/3 "2003-08-01T14:02:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Bongmaster](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bongmaster](https://boards.straightdope.com/u/Bongmaster)\
**Post date:** [August 1, 2003, 2:18pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/4 "2003-08-01T14:18:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yabob](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/yabob/32/2821_2.png) [@yabob](https://boards.straightdope.com/u/yabob)\
**Post date:** [August 1, 2003, 2:57pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/5 "2003-08-01T14:57:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![milk\_milk\_lemonade](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@milk\_milk\_lemonade](https://boards.straightdope.com/u/milk_milk_lemonade)\
**Post date:** [August 1, 2003, 3:11pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/6 "2003-08-01T15:11:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micco](https://avatars.discourse-cdn.com/v4/letter/m/5f8ce5/32.png) [@micco](https://boards.straightdope.com/u/micco)\
**Post date:** [August 1, 2003, 3:26pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/7 "2003-08-01T15:26:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bongmaster](https://avatars.discourse-cdn.com/v4/letter/b/6a8cbe/32.png) [@Bongmaster](https://boards.straightdope.com/u/Bongmaster)\
**Post date:** [August 1, 2003, 3:32pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/8 "2003-08-01T15:32:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LordVor](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LordVor](https://boards.straightdope.com/u/LordVor)\
**Post date:** [August 1, 2003, 3:42pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/9 "2003-08-01T15:42:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yabob](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/yabob/32/2821_2.png) [@yabob](https://boards.straightdope.com/u/yabob)\
**Post date:** [August 1, 2003, 9:18pm UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/10 "2003-08-01T21:18:25Z")

</div>

> [@](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Bill\_H](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@Bill\_H](https://boards.straightdope.com/u/Bill_H)\
**Post date:** [August 2, 2003, 12:17am UTC](https://boards.straightdope.com/t/lots-o-files-delete/192353/11 "2003-08-02T00:17:17Z")

</div>

cygwin baby [www.cygwin.com](http://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).
