document.write('<div class="python" style="font-family: monospace;"><br />');
document.write('<span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; FilesDeleter.py <br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Usage: python FilesDeleter.py [initial_dir] [string]<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Walks every subdirectory starting from<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; [initial_dir] and deletes every file in it that<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; contains in its file name \'string\'<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Example: python FilesDeleter.py . .class<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Deletes every .class file in all subdirs starting from current.<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />');
document.write('&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><br />');
document.write('<br />');
document.write('<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">sys</span><br />');
document.write('<br />');
document.write('<span style="color: #ff7700;font-weight:bold;">def</span> deletefiles<span style="color: black;">&#40;</span>dst, extension<span style="color: black;">&#41;</span>:<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> root, dirs, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>dst<span style="color: black;">&#41;</span>:<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> name <span style="color: #ff7700;font-weight:bold;">in</span> files:<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># If name ends with \'extension\' kill it</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>name.<span style="color: black;">rfind</span><span style="color: black;">&#40;</span>extension<span style="color: black;">&#41;</span>&gt;<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">\'deleting\'</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root, name<span style="color: black;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #dc143c;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root, name<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />');
document.write('<br />');
document.write('<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:<br />');
document.write('&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;FilesDeleter v.0.2&quot;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>&gt;<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; deletefiles<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>,<span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">else</span>:<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; FilesDeleter.py <br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Usage: python FilesDeleter.py [initial_dir] [string]<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Walks every subdirectory starting from<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; [initial_dir] and deletes every file in it that<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; contains in its file name \'string\'<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Example: python FilesDeleter.py . .class<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Deletes every .class file in all subdirs starting from current.<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <br />');
document.write('&quot;</span><span style="color: #483d8b;">&quot;&quot;</span><br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/300/1/" target="_blank">byteMyCode</a>.</div>');
