I am running several different unix commands as subprocesses (using python's subprocess module) from python that generate files that will be used later on in a pipeline. I'd like to know if there is an elegant way to get a list of the files generated by these subprocesses. Currently I am just using something like this:
self.fastQFiles = []
for filename in os.listdir(self.workdir):
if re.search(r'\.fastq$', filename, re.IGNORECASE):
self.fastQFiles.append(self.workdir + "/" + filename)
To search all files in a working directory and return only those that match a given extension. If this is the only way I can probably make my regex more complicated and match all the expected file types, but I'm a little concerned that old files that match will show up in the search too, I suppose I could add a datetime component as well, but that just feels clunky.
Is there a cleaner way to return the names of files generated by a subprocess?
EDIT: After thinking about this some more, the most elegant solution I can think of is doing this by collection subtraction.
preCounter = Counter(os.listdir('/directory'))
subprocess.(processArguments)
postCounter = Counter(os.listdir('/directory'))
newFiles = list(postCounter - preCounter)
If there's a better way to do this, I'm still open to suggestion.