How do i search directories and find files that match regex?
<p>I recently started getting into Python and I am having a hard time searching through directories and matching files based on a regex that I have created. </p>

<p>Basically I want it to scan through all the directories in another directory and find all the files that ends with <code>.zip</code> or <code>.rar</code> or <code>.r01</code> and then run various commands based on what file it is. </p>

<pre><code>import os, re

rootdir = "/mnt/externa/Torrents/completed"

for subdir, dirs, files in os.walk(rootdir):
    if re.search('(w?.zip)|(w?.rar)|(w?.r01)', files):
        print "match: " . files
</code></pre>