Clean-up map with pdf's

scallebe

Registered User.
Local time
Today, 21:21
Joined
Mar 23, 2018
Messages
51
Hi everybody,

I like to clean up a map where I store my pdf's (copies of reports)

I would like to delete all the pdf's who are older than 6 months from "today's date" using the modified date and not the creation date.

The web didn't bring me any solution so far...

my pdf's are stored in : CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"

Thanks in advance...

Greetz

Pascal :cool:
 
Code:
dim col As New Collection
dim sFile as string
dim sPath as string
dim i as long

sPath = CurrentProject.Path & "Verschilstaten - Decomptes - PDF\"
sFile = Dir(sPath & "*.pdf")
'save first before we delete
While sFile <> ""
    If DateValue(VBA.FileDateTime(sPath & sFile)) < DateAdd("m",-6 Date) Then
        col.Add sPath & sFile
    End If
    sFile = Dir
Wend
'we can delete it now
for i = 1 to col.Count
    VBA.Kill col(i)
next i
 
arnelgp,

Thanks for reply,

I think your code is working with the creation date of the pdf. Because I copied the complete map to my working map at home, all these dates are the same. The code should run with the "modified at" date. See picture (=Dutch)

Knipsel.JPG

Thanks

Greetz

Pascal :cool:
 
check first the modified date of your file at explorer.
if modified date and creation date are same...?
 
arnelgp,

No they are not, you can see the JPG I send. :)

The yellow dates are the modified dates, at the end you will see the creation date and they are all the same because of the copy yesterday.

I would like the code compere the modified date with today's date and delete all of them who are older than 6 months.

Thanks

Greetz

Pascal :cool:
 
Code:
Private Sub test()
    Dim fso As Object
    Dim oDir As Object
    Dim fil As Object
    Dim PDF_PATH As String
    Dim i As Long
    Dim col As New Collection
    PDF_PATH = CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"
    Set fso = CreateObject("scripting.filesystemobject")
    Set oDir = fso.getfolder(PDF_PATH)
    For Each fil In oDir.Files
        If fil.name Like "*.pdf" Then
            If fil.DateLastModified > fil.DateCreated and _
                DateValue(fil.DateLastModified) < DateAdd("m", -6, Date) Then
                col.Add fil.Path
            End If
        End If
    Next
    Set fil = Nothing
    Set oDir = Nothing
    For i = 1 To col.count
        fso.deletefile col(i)
    Next
    Set fso = Nothing
End Sub
 
Arnegp,

That's what I was looking for. :):)

I don't know why you want to compere the DateLastModified with the DateCreated. In my experience I know for shure that this date never changes. Once the pdf is created that date never change. We can not modifi or edit a pdf at work...

So I left this line out : "fil.DateLastModified > fil.DateCreated And _"

and it works perfect. The first pdf I see now is from 03/13/2019.

Thank you so much…

See you next time

Greetz

Pascal :cool:
 
you're the boss, just do what is best.
 
Good afternoon arnelgp,

In #6 you set a code to clean-up my PDF-folder. Works perfect:):)

I have a second pdf folder to clean-up the same way...

in following path :

Code:
CurrentProject.Path & "\Brieven Retour - Lettres retour - PDF"

How can I add the second folder into the code and do the clean-up in that folder to?

Thanks

Greetz

Pascal :cool:
 
Code:
Private Sub test()
    Dim fso As Object
    Dim oDir As Object
    Dim fil As Object
    Dim i As Long
    Dim j as integer
    Dim PDF_PATH As String
    Dim col As New Collection
    
    Dim arrPaths(1 To 2) As String
    
    arrPaths(1) = CurrentProject.Path & "\Verschilstaten - Decomptes - PDF"
    arrPaths(2) = CurrentProject.Path & "\Brieven Retour - Lettres retour - PDF"

    Set fso = CreateObject("scripting.filesystemobject")
    For j = 1 to Ubound(arrPaths)
        PDF_PATH = arrPaths(j)
        Set oDir = fso.getfolder(PDF_PATH)
        For Each fil In oDir.Files
            If fil.name Like "*.pdf" Then
                If DateValue(fil.DateLastModified) < DateAdd("m", -6, Date) Then
                    col.Add fil.Path
                End If
            End If
        Next
        Set fil = Nothing
        Set oDir = Nothing
        For i = 1 To col.count
            fso.deletefile col(i)
        Next
        Set col = New Collection
    Next j
    Set fso = Nothing
End Sub
 
arnelgp,

Thanks…

I am a little jealous of what you all realize as if it is nothing …

I also want to delve more into VBA, but time is not on my side at the moment...


Thanks again :):)

Greetz

Pascal :cool:
 

Users who are viewing this thread

Back
Top Bottom