今天闲来无事就捣鼓了一下python自带的os模块,看了下大概介绍,通过看视频就搞了一个实现递归删除图片的小程序
思路分析:
1,实现拼接目录和文件
2,在删除文件的情况下先做下判断,否则无法删除文件
import os
这里写代码片
encoding UTF-8
delete drive png
delte dirs png
date 2015-3-14 20:14
def getimage(path):
for file,root,trys in os.walk(path):
for files in trys:
if “png” in files:
imagefile=os.path.join(file+files)
#print imagefile
if “arr” in imagefile:
print imagefile
if os.path.isfile(imagefile): os.remove(imagefile)
path=”C:\Kugou”
getimage(path)