[Tutor] Filename match on file extensions

Dave Wilder D.Wilder at F5.com
Wed Oct 3 05:45:52 CEST 2012

>> 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
>>    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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121003/8fcd127a/attachment.html>

More information about the Tutor mailing list