Search Tools Links Login

Determine if File Is Old


Visual Basic 6, or VB Classic

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.

Original Author: Lewis Moten

Code

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 119 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.