[Tutor] Filename match on file extensions

Dave Wilder D.Wilder at F5.com
Wed Oct 3 05:14:16 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
else:
    result = 'FAIL'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121003/8a4075a5/attachment-0001.html>


More information about the Tutor mailing list