Creating a list of files in a directory
nospam!jklassen at biblesociety.ca
Wed Nov 7 18:47:39 CET 2001
I am new to Python. As a non-programmer I am encouraged by the level of
'success' I feel I have had, relative to similar learning attempts in other
I would like to simply do the following:
- read all of files of a particular form (e.g. *.cev) from a particular
- manipulate them with a series of re.sub expressions
- write each file to its own output file with a certain form (e.g. *.out).
I have been able to create the re stuff, and process individual files.
However, I cannot get a for loop to do everything in a directory.
Here is the code I came up with. (I am wanting to create a list of all files
that conform to *.cev)
filespec = re.compile(r'.*?\.cev')
filestoprocess = 
for allfiles in workingdir:
When I run this script I am returned:
AttributeError: 'None' object has no attribute 'group'
When I issue these commands in the Python Shell, substituting an actual
value for allfiles such as 'mat.cev', everything works OK. I can execute
filestoprocess.append(matchedfile.group()) and then print filestoprocess,
and I am returned ['mat.cev']. Why does this fail to work inside of the
Thanks very much for any help.
More information about the Python-list