A way of determining if a file is available


Using the example below is it possible to check the file / path exists and/or is available.

1) In order to produce an invoice I "import" a company logo to produce a pdf that gets printed.

2) the company logo is stored in the following location //

However if the path or filename doesn't exist then the program seems to hang for 1 minute or 2 before carrying on.

So my question is - is there a Cobol way to check the file or path exists first, which is hopefully quicker, before I try and attach it?

Many thanks


  • You might try using:

        using    filename
        returning status-code

  • Hi Chris,

    Ok that doesnt work if the IP address of the server if not on the network or you dont have permissions i.e it just seems to "hang" for a while before it returns.

    So if my file exists on

    But I'm actually checking

    Is there any way of checking that with out a delay?

    Many thanks


  • I'm afraid not - at least not in any simple fashion.

    The file path you're using is a UNC path - it refers to a file on a remote system, accessed via SMB (Microsoft file sharing). The delay you're seeing is the SMB resolver attempting to open a connection to the specified IP address, establish a session, verify the credentials of the user account under which your program is running, request the share (in this case "Shared") named in the path, query the contents of that share, see if it contains the next level of the path ("Data"), open that as a directory, see if it contains an entry called "CompanyLogo.jpg", open that, and read its contents.

    Nearly all of the time is spent before the final two steps (opening CompanyLogo.jpg and reading it), so there's essentially no difference in wall-clock time between simply opening the UNC path and using an API such as CBL_CHECK_FILE_EXIST.

    There's no way to check for the existence of the file "without a delay" because the computer your application is running on doesn't know the answer. It has to communicate with the remote system, and that takes time. (A lot of time, frequently, in the case of SMB, which is a fairly dumb protocol; and it's running over TCP/IP, which by design keeps trying for a while if it doesn't succeed at first. TCP/IP was not intended for the impatient.)

    There are ways to avoid some of this delay in some cases where you can tell you won't be able to get the file - for example by checking whether the destination host is reachable at all. There are ways to hide the delay, by retrieving the file in a background thread while your application is doing other work. There are ways to avoid taking the delay every time, by caching the file locally. But none of these are trivial.