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
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » PC hardware » Questions – Maintenance and backups » Automatically deleting old files
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, revisted
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,
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 download.com or another freeware site.
Theodore,
This is a piece of cake w/PowerShell
To find your old files:
[noparse]get-childitem -path G:BEKDocs*.* -Recurse | where LastAccessTime -lt 1/1/2007 | select fullname, Lastaccesstime[/noparse]
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:
[noparse]get-childitem -path G:BEKDocs*.* -Recurse | where LastAccessTime -lt 1/1/2007 | foreach ($_) {remove-item $_.fullname}[/noparse]
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!
HTH :cheers:
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications