(PYVMS LOGO) Python on OpenVMS

(go to: table of contents, index, list of vms_lib, prev: FID_TO_NAME, next: FIND_FILE_END)


FIND_FILE - Find File


Search for files.

Please note that You MUST check status (and status_value) because FIND_FILE() does NOT raise an exception when something goes wrong!

Format:

    status, status_value, context, resultant_filespec = \
        vms_lib.find_file (filespec, context, \
            [default_filespec], [related_filespec], [flags])
Returns:
status
The return-status from LIB$FIND_FILE.
status_value
RMS status (FAB$L_STV) if the operation failed.
context
A context value for future calls to FIND_FILE.
resultant_filespec
Resultant file specification that LIB$FIND_FILE returns when it finds a file that matches the specification in the filespec argument.
Arguments:
filespec
File specification, which may contain wildcards, that LIB$FIND_FILE uses to search for the desired file.
context
A context value from a previous call to FIND_FILE. Use 0 for the first call.
default_filespec
Default file specification. See the OpenVMS Record Management Services Reference Manual for information about default file specifications.
related_filespec
Related file specification containing the context of the last file processed.
flags
See the description of LIB$FIND_FILE for details. According to the documentation (OpenVMS VAX V6.1) there are no symbolic names available to define these bits.
Examples:
$! create test area
$ create/directory [.TMP_FF]
$ copy _NLA0: [.TMP_FF]FF_1.TMP
$ copy _NLA0: [.TMP_FF]FF_2.TMP
$ copy _NLA0: [.TMP_FF]FF_3.TMP
$ copy _NLA0: [.TMP_FF]FZ_1.TMP
$ copy _NLA0: [.TMP_FF]FZ_2.TMP
$ copy _NLA0: [.TMP_FF]FZ_2.ZZZ

$ python
[ banner page omitted ]
>>> import vms_lib
>>> import vms_sys
>>> import string

>>> context = 0
>>> status, status_value, context, resultant_filespec = \
...   vms_lib.find_file ('[.TMP_FF]FF_*.TMP', context, \
...   None, None, 1) # 1=NOWILD
>>> 
>>> status, status_value, context, resultant_filespec
(1380650, 0, 2103296, None)
>>> vms_sys.getmsg (status)
('%LIB-E-NOWILD, no wildcard permitted', (0, 0, 0, 0))
>>> print vms_lib.find_file_end (context)
None
>>>
>>> # retry to deallocate an already deallocated context
>>> vms_lib.find_file_end (context)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
vms_lib.error: (99596, '%RMS-F-FAB, invalid FAB or FAB not accessible')
>>>


>>> context = 0
>>> status  = 1
>>> while (status & 1):
...   status, status_value, context, resultant_filespec = \
...     vms_lib.find_file ('[.TMP_FF]FF_*.TMP', context, \
...     None, None, 0) # 0 = allow wildcards
...   status, status_value, context
...   if (resultant_filespec != None):
...     string.strip (resultant_filespec)
...   else:
...     vms_sys.getmsg (status)
...     vms_sys.getmsg (status_value)
...     break  # reached end
...
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_1.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_2.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_3.TMP;1'
(99018, 2352, 0)
('%RMS-E-NMF, no more files found', (0, 0, 0, 0))
('%SYSTEM-W-NOMOREFILES, no more files', (0, 0, 0, 0))
>>>
>>> # loop completed, context is deallocated
>>> print context
0
>>>
>>> # show a 'success' status value:
>>> vms_sys.getmsg (65537)
('%RMS-S-NORMAL, normal successful completion', (0, 0, 0, 0))
>>> # a status_value of 0 also means no error has accured


>>> context = 0
>>> status, status_value, context, resultant_filespec = \
...   vms_lib.find_file ('[.TMP_FF]FF_*.TMP,FZ_*.*', context, \
...   None, None, 0) # 0 = no multiple, but wildcards allowed
>>> status, status_value, context
(100052, 0, 2104624)
>>> vms_sys.getmsg (status)
('%RMS-F-SYN, file specification syntax error', (0, 0, 0, 0))
>>>
>>> # WARNING! There is a context left!
>>> print context
2104624
>>> # deallocate it
>>> vms_lib.find_file_end (context)
None
>>>


-- use multiple and provide a default-filespec

$ define FF_LNM FF_*,FZ_*    ! logical name search list

>>> context = 0
>>> status = 1
>>> while (status & 1):
...   status, status_value, context, resultant_filespec = \
...     vms_lib.find_file ('FF_LNM', context, '[.TMP_FF].TMP', \
...     None, 2) # 2 = multiple and wildcards allowed
...   status, status_value, context
...   if (resultant_filespec != None):
...     string.strip (resultant_filespec)
...   else:
...     vms_sys.getmsg (status)
...     vms_sys.getmsg (status_value)
...     break  # reached end
...
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_1.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_2.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FF_3.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FZ_1.TMP;1'
(65537, 0, 2104624)
'DKA100:[PYTHON.PYTHON-1_5_1.VMS.TMP_FF]FZ_2.TMP;1'
(99018, 2352, 2104624)
('%RMS-E-NMF, no more files found', (0, 0, 0, 0))
('%SYSTEM-W-NOMOREFILES, no more files', (0, 0, 0, 0))
>>>
>>> # a context is still active, because - according to the
>>> #  documentation - the data from the previous call is saved
>>> #  to be used as the related filespecification on the next
>>> #  call
>>> print context
2104624
>>> # deallocate it
>>> vms_lib.find_file_end (context)


>>> import vms_sys
>>> vms_sys.getmsg (status)[0]
'%SYSTEM-S-NORMAL, normal successful completion'
>>>

$! delete test area
$ set PROTECTION=O:RWED [.TMP_FF]*.*;*, []TMP_FF.DIR;*
$ delete [.TMP_FF]*.*;*, []TMP_FF.DIR;*

(go to: table of contents, index, list of vms_lib, prev: FID_TO_NAME, next: FIND_FILE_END)

25-DEC-1998 ZE.