1 2 3 4 5 6 7 8 | #!/usr/bin/env python
import os
directory = os.listdir('.')
for filename in directory:
if filename[-3:] == 'pyc':
print '- ' + filename
os.remove(filename)
|
1 2 3 4 5 6 7 8 | #!/usr/bin/env python
import os
directory = os.listdir('.')
for filename in directory:
if filename[-3:] == 'pyc':
print '- ' + filename
os.remove(filename)
|
Comments
And when would you use that instead of "rm *.pyc"? Or maybe "find -name '*.pyc' -print0|xargs -0 rm" to also remove .pyc files in subfolders?
#
It's clearly a time saver.
#
or "find . -name ".pyc" -exec rm -rf {} ;"
#
Or simpler:
find -name "*.pyc" -delete
#
It could be useful if it can delete all the .pyc in directory tree.
#
Thanks all, the bash script seems much more useful.
#
personally i like:
find -type f -name "*.py[co]" -delete
#