Optimizing simple Python file matching & replacement script
<p>just wondering if anyone has a suggestion for how I can optimize my simple but slow file replacement script:</p>

<pre><code>def switchFiles(args):
for root1, dirs1, files1 in os.walk(args.folder):
    for f1 in files1:
        for root2, dirs2, files2 in os.walk(args.database):
            for f2 in files2:
                if fnmatch.fnmatch(f1, f2):
                    command = 'cp '+os.path.join(root1, f1)+' '+os.path.join(root2, f2)
                    print(command)
                    os.system(command)
</code></pre>

<p>Thanks! </p>
