#! /usr/bin/env python ############################################################## # # Name: parse_results.py # # Description: read and parse stored results # # Usage: # # # Author: Jun Wang j.wang@ewi.tudelft.nl # ############################################################## import os.path, fnmatch import os def listFiles(root, patterns='*', recurse=1, return_folders=0): # Expand patterns from semicolon-separated string to list pattern_list = patterns.split(';') # Collect input and output arguments into one bunch class Bunch: def __init__(self, **kwds): self.__dict__.update(kwds) arg = Bunch(recurse=recurse, pattern_list=pattern_list, \ return_folders=return_folders, results=[]) def visit(arg, dirname, files): # Append to arg.results all relevant files(and perhaps folders) for name in files: fullname = os.path.normpath(os.path.join(dirname,name)) if arg.return_folders or os.path.isfile(fullname): for pattern in arg.pattern_list: if fnmatch.fnmatch(name, pattern): arg.results.append(fullname) break # Block recursion if recursion was disallowed if not arg.recurse: files[:]=[] os.path.walk(root, visit, arg) return arg.results thefiles = listFiles('/home3/jwang/scratch', '*.bz2') for i in range(len(thefiles)): print thefiles[i] cmd = 'bunzip2'+' '+ thefiles[i] os.system(cmd) thefiles = listFiles('/home3/jwang/scratch', 'buddycast-log*') for i in range(len(thefiles)): print thefiles[i]