VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Determine if File Is Old

by Lewis E. Moten III (9 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Determines if a file is old. I use this when I loop through the files in a "temp" directory to determine if I should delete old files on a website. Take note - the function looks at the last modified date rather then the date created.

Rate Determine if File Is Old

Private Sub Form_Load()
  MsgBox IIf(FileIsOld("C:\AutoExec.bat"), "The file is old", "The file is new")
End Sub
Function FileIsOld(ByRef pStrFilePath As String) As Boolean
  
  Dim llngMinutesOld As Long
  Dim ldtmLastModified As Date
  Dim llngFileAttr As VbFileAttribute
  
  Const llngMinutesOldAfter As Long = 10
    
  On Error Resume Next
  
  llngFileAttr = FileSystem.GetAttr(pStrFilePath)
  
  If Err Then
    MsgBox "File does not exist."
    Exit Function ' file doesn't exist
  End If
  
  On Error GoTo 0
  
  If Len(FileSystem.Dir(pStrFilePath, llngFileAttr)) = 0 Then Exit Function
  
  ldtmLastModified = FileSystem.FileDateTime(pStrFilePath)
  
  llngMinutesOld = DateDiff("n", ldtmLastModified, Now())
  
  FileIsOld = llngMinutesOld > pLngMinutesOldAfter
End Function

Download this snippet    Add to My Saved Code

Determine if File Is Old Comments

No comments have been posted about Determine if File Is Old. Why not be the first to post a comment about Determine if File Is Old.

Post your comment

Subject:
Message:
0/1000 characters