Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error Resume Next being ignored

Status
Not open for further replies.

ChrisQuick

Programmer
Oct 4, 1999
144
US
Hi:

We have an application that generates HTML and jpeg files for a wed-based mapping application. We have a sub routine written to periodically go out and delete these files once the are older than 15 minutes. Here is our code:

Code:
Private Sub tmrDelete_Timer()
    
  If intTimerCount <= 5 Then
        
    intTimerCount = intTimerCount + 1
        
  Else
        
    Dim strFileName As String
    Dim tmpFileObj As Object
    Dim tmpFileSpec As Object
    Dim tmpFileDateTime As Variant
        
    Set tmpFileObj = CreateObject(&quot;Scripting.FileSystemObject&quot;)
        
    strFileName = Dir(&quot;d:\imsscratch\*.*&quot;)
    If strFileName <> &quot;&quot; Then
            
      Do Until strFileName = &quot;&quot;
        Set tmpFileSpec = tmpFileObj.GetFile(&quot;d:\imsscratch\&quot; & strFileName)
        tmpFileDateTime = tmpFileSpec.DateCreated
        If DateDiff(&quot;n&quot;, tmpFileDateTime, Now) >= 15 Then
          On Error Resume Next
          Kill &quot;d:\imsscratch\&quot; & strFileName
          Err.Clear
        End If
        strFileName = Dir
      Loop
            
    End If
    
    Set tmpFileObj = Nothing
    intTimerCount = 0
        
  End If
    
End Sub


Every now and then the application will throw an error &quot;file not found&quot; on the line with the kill statement, so we added the On Error Resume Next, and the Err.Clear hoping it would supress the error and allow the app to keep working. But we are still getting the &quot;file not found&quot; error anyway.

Any ideas on why the On Error Resume Next is being ignored?
Any ideas how a file that supposedly can't be found, can have it's date created returned? After all, we are only trying to delete files older that 15 minutes, so if the file didn't exist, how would we know it's age? cquick@geotg.com
Geographic Information System (GIS), ASP, some Oracle
 
I suspect the error is occuring before your On Error statement. Move the On Error to the first line of the sub.

Also, if you are already using the FileSystemObject, why not use its DeleteFile method rather than VB's &quot;Kill&quot; to wax your file?
 
Upon further reflection I have to ask why you are using On Error Resume Next in the first place. This should (in my opinion) be used only when you know a routine either will, or could, return an error, but you don't care about it.

&quot;File Not Found&quot; returns an error that can be easily trapped and appropriately dealth with.
 
Well my first concern is how could a file show up in the list returned by the Dir yet somehow not be found? To me that makes no sense whatsoever.

As to why we're using On Error Resume Next, the fact is we don't care if it returns an error when trying to delete the file. We can always try to delete it again in the next cycle. cquick@geotg.com
Geographic Information System (GIS), ASP, some Oracle
 
Code:
    Dim strFileName As String
    Dim tmpFSO As Object
    Dim tmpFiles as object
    Dim tmpFile  as object
    Dim tmpFileDateTime As Variant
    Dim strPath as string
    strPath = &quot;d:\imsscratch&quot;    
    Set tmpFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    With tmpFso
        Set tmpFiles = .GetFolder(strPath)
        For Each tmpFile In tmpFiles 
            tmpFileDateTime = tmpFile.DateCreated
            If DateDiff(&quot;n&quot;, tmpFileDateTime, Now) >= 15 Then
                On Error Resume Next ' In case other App deletes
                    .Delete(.BuildPath(strPath,tmpFile.Name))
                on Error Goto 0  ' Resets
            End If
        Next            
    End With 
   
    Set tmpFSO = Nothing
    Set tmpFiles = Nothing
    Set tmpFile = Nothging
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top