Advertisement
6_2008-2009 Files/ File Controls/ Input/ Output #199868

Determine if File Is Old

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.

AI

AI 摘要: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

源代码
original-source
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
原始评论 (3)
从 Wayback Machine 恢复