Error 53 when testing file existence with Dir() function, FSO as an alternative?

Posted on 2006-05-10
Last Modified: 2013-11-13
My app is transmitting files using a winsock TCP connection.  I send the file in chunks (waiting for confirmation of each send before sending the next chunk to prevent overrunning the bandwidth).  Before I put a file on the wire, as well as at the start of each chunk,  I check to make sure the file exists and it is the same one I started with (i.e., filesize and filetimestamp are the same).  

Code I am using to test the file is as follows:

If Dir(.qData(qpFilename)) = "" Then                       ' Check if File exists
                        ' File is not present - Flag it as Invalid
                        blnFileInvalid = True
                        ' File was found, check it's timestamp and size to see it is the current one
                        If FileLen(.qData(qpFilename)) = FSize And FileDateTime(.qData(qpFilename)) = FTime Then
                            blnFileInvalid = False
                            blnFileInvalid = True
End If

My problem is that I occassionally get an Error 53 (File not found) thrown in the Dir() statement (I have no on error in the routine).  I have also occassionally see the Error 53 in the FileLen() and FileDateTime() routines after the file existence has been successfully checked.

The file I am accessing/sending is on a network share.  It is refreshed periodically by another routine running on the machine hosting the network share.  I have a suspicion  that the other machine/routine is active (the other machine is a 2-way system) and that the a new file is being swapped in when my code above is trying to access the file (and the "File not found" error is thrown because the file is locked while being written/renamed, not because it is missing).  

1) Can anyone verify whether things like file locking (and/or other network share redirector access) can cause these Error 53's?

2) Will converting the code to use FileSystemObject constructs for the tests eliminate the problem?

3) I was thinking of leaving the file open for read (so that it will be locked out from being updated/replaced) during the 3.6 seconds (on average) that it takes to transmit (and let the other program deal with the "lock" issue.  This will prevent the file from disappearing with each open I do to send another chunk.  This still doesn't prevent the locking conflict (and error 53) from occurring on the first chunk to be sent.  Can anyone suggest an alternative reason for the errors and a solution?


Question by:KenLevy0509
    1 Comment
    LVL 142

    Accepted Solution

    1) no
    2) yes

    the best way to avoid incomplete file transfers, is to let the transfer put a control file that tells you that the transfer is complete.
    I have changed last week an application in this way, and now the process works flawlessy, whereas beforehand there where all over the time incomplete files used...

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now