 <p>Based on your example, you are trying to delete all files present within some folder. Instead of iterating over all the files of the folder, and delete each file individually, the better way is to use <a href="https://docs.python.org/2/library/shutil.html" rel="nofollow">shutil.rmtree()</a>. It will recursively delete all the files for the given path (similar to <code>rm -r /path/to/folder</code> in unix).</p> <pre><code>import shutil shutil.rmtree('/path/to/folder') </code></pre>