HP OpenVMS Systems

ask the wizard
Content starts here

Managing Files, File Transfers?

» close window

The Question is:

What is the best way to determine if a file is already
open?  Particularly using a Perl script to process a
directory of incoming files and want to skip any files
still being transferred.  I suppose I could parse the
output of "$ show device/files device" but I only need
open info on selected file or directory.  Thanx

The Answer is :

  The answer depends on why you need to know if the file is open.
  If it's because you want to know if you will receive an error
  message you attempt to open the file, then the best approach is
  to simply attempt to open the file and recover from any error
  conditions.  Why?  In a multi-processing operating system such
  as OpenVMS, any other mechanism you might use will be subject
  to timing windows -- the file might be opened between your probe
  and your subsequent attempt to open the file.
  The same argument applies to determining if there is sufficient
  disk space to create a file, adequate privileges to read or write
  a file, or indeed anything which is not a permanent property.
  (As an example of a somewhat more permanent property, consider
  the existence of a disk.)
  For your case, of a directory of files waiting to be processed,
  you are probably better off having another directory on the same
  disk to park the files being processed.  Let's call them [PENDING]
  (your existing directory) and [TRANSIT].  When you find a file that
  needs to be processed, RENAME it from [PENDING] to [TRANSIT], and
  commence processing. Since the processing then appears to be
  more-or-less instantaneous to observers of the [PENDING] directory,
  you avoid the issue completely.

answer written or last revised on ( 10-JUN-2002 )

» close window