>> Hello,
>> Below is a snippet of a search I want to do for any file that contains the >> string "quarantine" in the filename. >> It works for picking up any file name containing "quarantine" except when >> "quarantine" is used as an extension. >> For example, the search would find quarantine.txt but fails to find >> txt.quarantine. I have done some investigating, but have >> Not been able to determine how to make it include extensions in the search. >> I believe I should be using something like "os.path.splitext". Does that >> make sense? Thanks. >> target = '/home' >> matches = 0 >> for (currdir,subdirs,files) in os.walk(target): >> for i in files: >> if i.lower().find("quarantine".lower()) == 0: ## Case-insensitive search >> for string "quarantine" in filename >> matches += 1 # increment number of matches >> print "Quarantine file",i,"found in directory",currdir >>if matches > 0: >> result = tc.FAIL >>else: >> result = 'FAIL' > Would this be a time when regex is necessary? Maybe: > \b[^.]*quarantine[^.]*\.[a-zA-Z]*\b I had originally used regular expression, but thought there might be a simpler solution w/o the need for regular expressions. If that is what is needed, then so be it though. Thank you for your quick response.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor