• Automatically deleting old files

    Home » Forums » AskWoody support » PC hardware » Questions – Maintenance and backups » Automatically deleting old files

    Author
    Topic
    #500748

    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

    Viewing 4 reply threads
    Author
    Replies
    • #1513177

      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

    • #1513385

      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.
    • #1513495

      To be more precise–

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

      Zig

    • #1523952

      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.

    • #1523965

      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:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    Viewing 4 reply threads
    Reply To: Automatically deleting old files

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: