Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Feb 2009
    Evanston, Illinois, USA
    Thanked 0 Times in 0 Posts

    Automatically deleting old files

    How can I automatically delete hundreds of old files (from before the year 2000) and keep only files with latest saved date ?? Can I use DOS batch files to accomplish this task ??

    Thanks for any help ... Theodore

  2. #2
    Silver Lounger RolandJS's Avatar
    Join Date
    Dec 2009
    Austin metro area TX USA
    Thanked 145 Times in 142 Posts
    Probably can. I would pretend DIR was the delete command and experiment until the DIR commands give you exactly what you want -- a listing of the files that would have been deleted if the DEL command was used. After you're satisfied, subsitute DEL for DIR [of course change a switch or two], test on a directory with files you can afford to lose before committing batchfile to the whole data partition.
    "Take care of thy backups and thy restores shall take care of thee." Ben Franklin revisited.
    Backup, backup, backup! -- Lady Fitzgerald (sevenforums)
    Clone or Image often! Backup, backup, backup, backup... -- RockE (Windows Secrets Lounge)

  3. #3
    5 Star Lounger
    Join Date
    Oct 2013
    Phoenix, AZ
    Thanked 137 Times in 128 Posts
    Quote Originally Posted by Theodore View Post
    How can I automatically delete hundreds of old files (from before the year 2000) and keep only files with latest saved date ?? ....
    Are they in the same folder? If so,
    • Open Windows Explorer.
    • Sort by date.
    • Highlight the first file you want to delete.
    • Then go to the last file, hold down the shift key and highlight the last file you want to delete.
    • All the files you want to delete should now be highlighted. Hit the delete key.

  4. #4
    5 Star Lounger
    Join Date
    Dec 2009
    S.F. Bay Area, California, USA
    Thanked 85 Times in 83 Posts
    To be more precise--

    While holding the shift key down, press the delete key.


  5. #5
    2 Star Lounger
    Join Date
    Dec 2009
    Chicago, IL, USA
    Thanked 2 Times in 2 Posts
    You can do it in a batch file with some advanced commands but it's very tricky. There are some books on advanced batch file programming (including one by Peter Norton) that might be helpful, if you want to put some time into it, or you can google the topic. If you only want to do it once it probably isn't worth the trouble.

    There are also some utilities that will delete files by date. You might look on or another freeware site.

  6. #6
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Manning, South Carolina
    Thanked 1,608 Times in 1,452 Posts

    This is a piece of cake w/PowerShell

    To find your old files:

    get-childitem -path G:\BEKDocs\*.* -Recurse | where LastAccessTime -lt 1/1/2007 | select fullname, Lastaccesstime

    Substituting your own value for the -path argument, remembering to enclose it in quotes if it includes spaces, and your cutoff date. Note that is a Less Than (-lt) so the date you enter will NOT be listed or deleted only files older than that date. Also note the -Recurse parameter which means that the command will operate on all sub-directories below the main directory you specify in the -path parameter. If you don't want this behavior just remove the -Recurse.

    When satisfied with the list to delete them:

    get-childitem -path G:\BEKDocs\*.* -Recurse | where LastAccessTime -lt 1/1/2007 | foreach ($_) {remove-item $_.fullname}

    If you've never done PS before see: this previous post of mine.

    As always before doing this type of operation make sure you have a COMPLETE BACKUP or IMAGE of the directory tree you are going to operate on. Preferably a complete Drive Image!

    Last edited by RetiredGeek; 2015-08-19 at 16:43.
    May the Forces of good computing be with you!


    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  7. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Fascist Nation (2015-08-19)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts