下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
#!/usr/bin/env python
import os
import shutil
delList = []
delDir = "/home/test"
delList = os.listdir(delDir )
for f in delList:
filePath = os.path.join( delDir,f )
if os.path.isfile(filePath):
os.remove(filePath)
print filePath + " was removed!"
elif os.path.isdir(filePath):
shutil.rmtree(filePath,True)
print "Directory: " + filePath +" was removed!"
shutil是一个高层次的文件操作模块。True参数表示ignore_errors(忽略拷贝时候的错误)。
类似于高级API,而且主要强大之处在于其对文件的复制与删除操作更是比较支持好。
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。