?
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
Medium Priority
?
780 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

801 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