Python and CRTL and file searching

Post Reply

Topic author
jeremybegg
Contributor
Posts: 17
Joined: Mon Jun 08, 2020 3:39 am
Reputation: 0
Status: Offline

Python and CRTL and file searching

Post by jeremybegg » Mon Jun 08, 2020 3:59 am

Hi,

I am beginning to explore Python again after an absence of several years. I was running Python 2.7 on VMS a few years ago and wrote some scripts to do useful things.

Recently I installed the Python 3.5 (beta) release from VSI and started testing my scripts. One of them made use of the CRTL's from_vms() and to_vms() functions to translate filenames from VMS ODS-5 syntax to the Unix-style syntax assumed by Python.

Under Python 2.7 I could pass a wildcard VMS filespec to the script which would be expanded into a list of matching files:

Code: Select all

#-------------------------------------------------------------------------------
# Build a list of files to process
#
import vms.crtl

Files = []
for f in sys.argv[1:]: Files = Files + vms.crtl.from_vms(f,True)
But in the CRTL module included in Python 3.5, the from_vms() function only has only one argument (the VMS filespec) and given a wildcard it returns an empty list. I tried calling the builtin glob() function but it does not work with a VMS-format file and directory specification (e.g. DIR:*.TXT), it must be specified as /DIR/*.TXT.

So how should my script process a file specification which includes wildcards and VMS-format device & directory or logical names?

Thanks,
Jeremy Begg


jfp
Contributor
Posts: 16
Joined: Wed Jun 17, 2020 6:34 am
Reputation: 0
Status: Offline

Re: Python and CRTL and file searching

Post by jfp » Sat Jun 20, 2020 5:16 am

Hi Jeremy,

Or you can use the FindFile class
Exemple:

Code: Select all

from vms.rtl.lib import FindFile
with FindFile.FindFile(b'*.com') as ifn:
   for fn in ifn:
      print(fn)
gives

Code: Select all

b'DISK$REPOS:[OpenVMS.python.cpython310.vms]bootstrap.com;1'
b'DISK$REPOS:[OpenVMS.python.cpython310.vms]link.com;40'
b'DISK$REPOS:[OpenVMS.python.cpython310.vms]link_py.com;1'
b'DISK$REPOS:[OpenVMS.python.cpython310.vms]logicals.com;1'
b'DISK$REPOS:[OpenVMS.python.cpython310.vms]logicals_dev.com;3'
b'DISK$REPOS:[OpenVMS.python.cpython310.vms]python_compiler_options.com;1'
JF

Post Reply