Solved

VB Returns an Error 53 (File Not Found) when executing fso.FolderExists but folder exists on the local machine

Posted on 2006-11-13
4
771 Views
Last Modified: 2013-12-26
I have an VB 6.0 application that periodically (once a minute) looks for any text file in a particular folder.  This folder exists on the local machine where the VB application is running.  Folder path is hard coded in an "ini" file at startup.  99% of the time, this function works properly, but about once a month Error 53 (File Not Found) is returned.  It seems to occur for 15-30 minutes, then finds the folder again with no user intervention.

This system pages me 24/7 if the files are not processed, so I would love to figure this one out.  Any ideas?

Here is the code:

Public Function LookForInputFile() As Boolean
    Dim ExtString As String
    Dim PathString As String
    Dim fso2 As New FileSystemObject
    Dim fileExists As Boolean
   
    ExtString = "*.txt"
    PathString = autoDetectFilePath & ExtString
   
    If fso2.FolderExists(autoDetectFilePath) Then
        filAutoDetect.FileName = PathString
        lblAutoDetect.Caption = PathString
        filAutoDetect.Refresh
        If filAutoDetect.ListCount > 0 Then 'file or files found
            LookForInputFile = True
            '
            ' Do some processing based on unique file names
            '
        ElseIf filAutoDetect.ListCount = 0 Then
            LookForInputFile = False
        End If
    Else
        LookForInputFile = False
    End If
End Function
0
Comment
Question by:sainiak
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17931012
Would love to help out...but what exactly is "filAutoDetect"?
0
 

Author Comment

by:sainiak
ID: 17931763
filAutoDetect is a File List Box.  It displays the files in the PathString.
Based in the logging I do, I don't think it is getting that far in the code.  
I think the error is occurring on the "If fso2.FolderExists(autoDetectFilePath) Then" statement.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 18010758
It isn't clear if where the autoDetectFilePath value comes from.

I would suggest that you write to a log file at strategic points.

Public Function LookForInputFile() As Boolean
    Dim ExtString As String
    Dim PathString As String
    Dim fso2 As New FileSystemObject
    Dim fileExists As Boolean
   
    ExtString = "*.txt"
    PathString = autoDetectFilePath & ExtString
   WriteLog "LookForInputFile: Pathstring = " & PathString
    If fso2.FolderExists(autoDetectFilePath) Then
      WriteLog "LookForInputFile: Folder " & autoDetectFilePath & " found"
      filAutoDetect.FileName = PathString
        lblAutoDetect.Caption = PathString
        filAutoDetect.Refresh
        WriteLog "LookForInputFile:  ListCount = " & filAutoDetect.ListCount
        If filAutoDetect.ListCount > 0 Then 'file or files found

            LookForInputFile = True
            '
            ' Do some processing based on unique file names
            '
        ElseIf filAutoDetect.ListCount = 0 Then
            LookForInputFile = False
        End If
    Else
        LookForInputFile = False
        WriteLog "LookForInputFile: Folder " & autoDetectFilePath & " not found"

    End If
End Function

The built-in logging doesn't work in design mode, so I use one like this:

Sub WriteLog(strText As String)
    Dim strText1 As String
    Dim f As Integer
    Dim strFile As String
    strFile = "C:\Documents and Settings\User Name\My Documents\fil" & Format$(Now, "yyy") & ".Log"
    f = FreeFile
    strText1 = Format$(Now, "hh:nn:ss ") & strText
    Debug.Print strText1
    Open strFile For Append As #f
    Print #f, strText1
    Close #f
End Sub

Also you might like to try a different test for the folder:

If Dir$(autoDetectFilePath, vbDirectory) <> "" Then

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How does CurrentUser work? 10 38
MS Date Picker 64 bit 32 bit issue 12 60
Spell Check in VB6 13 126
Protecting vb6 & .Net code Obfuscation 18 151
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question