• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Delete older files and keep latest files

I have code which deletes files listed in 'A' column with dir path.
I have also code that list all files from selected dir.
Now I wanted to delete older files and keep latest files.
Code to delete files:
Code:
Sub DeleteExample3()
    Dim c As Range, f As String
    For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
        f = c.Value2 & c.Offset(0, 1).Value2
      Kill f
    Next c
     
    On Error GoTo 0
End Sub
 

Attachments

  • Deletefiles.PNG
    Deletefiles.PNG
    57.3 KB · Views: 10
Hi,

I think you will need to be a bit more specific :)
Exactly how old must the files be to be deleted?
Since you already have the "Last modified" dates there it should be quite simple to "kill" only those which fall within the "older than x days" category.
 
Hi,

Actually I wanted to consider duplicate files from "B" column because these are files that I am interested in. Then go to "D" column sort according to dates -> Delete all file versions except latest one. What I have code is to delete all files. I am unable to figure out latest files to keep it and delete older ones.
 
Monty,
Thank for the reply!
I mean if I have 3 versions of 'test.txt' on machine at different location. I am interested in latest one. So wanted script which will delete older versions of those files keeping latest one.
Note that there will not be any particular date by which we can sort files. We will have to get files which are located in more than one location and then find latest to skip from deleting and delete rest of the versions of that/those files.
 
Hi,
But I have many such files so i am in serach of script or formula which will show in column text that this is latest fileb and these/this is older file/s and user will have ability to click one a single button that will run script to delete all older files or there will be link upon which clicking, the respective file will be deleted.
 
Back
Top