分类: LINUX
2008-09-23 13:23:29
#!/usr/bin/python #filename: dir.py import os from os.path import join from os import chdir,remove for root,dirs,files in os.walk('/home/lsj'): for file in files: if file[-1:]=='~'or file[-4:]=='.swp': print 'delete file is:',join(root,file) chdir(root) remove(file) print 'Program Finish' |
Note: The newer os.walk() generator supplies similar functionality and can be easier to use. |
raceback (most recent call last): File "./dir.py", line 12, in ? remove(file) OSError: [Errno 2] No such file or directory: 'Main.cpp~' |