一个清理svn,.pyc,CVS等等文件,目录的小脚本

文件见附件

可以根据需要修改 DEL_LIST 来指定需要清理的内容
python 代码
  1. DEL_LIST=[
  2. r'^\.svn$',
  3. '^CVS$',
  4. r'.*\.pyc$'
  5. ]
  6. from os.path import join
  7. import os
  8. from os import getcwd,walk,rmdir,chmod
  9. import re
  10. import stat
  11. def write_able(name):
  12. path=join(root,name)
  13. chmod(path,stat.S_IWRITE)
  14. return path
  15. remove=lambda name:os.remove(write_able(name))
  16. def del_dir(dir):
  17. for root, dirs, files in walk(dir,topdown=False):
  18. for name in files:
  19. remove(name)
  20. for name in dirs:
  21. rmdir(write_able(name))
  22. rmdir(dir)
  23. DEL_LIST=[re.compile(i) for i in DEL_LIST]
  24. for root, dirs, files in walk(getcwd(),topdown=False):
  25. for i in DEL_LIST:
  26. j=''
  27. def if_match(func):
  28. if i.match(j):
  29. func(join(root,j))
  30. print join(root,j)
  31. for j in dirs:
  32. if_match(del_dir)
  33. for j in files:
  34. if_match(remove)
  35. raw_input('*'*61+'\nFinished')

你可能感兴趣的:(linux,SVN,脚本,OS,cvs)