通过本文主要向大家介绍了python 创建文件夹,python 遍历文件夹,python 删除文件夹,python读取文件夹,python 文件夹等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了Python实现删除当前目录下除当前脚本以外的文件和文件夹。分享给大家供大家参考。具体如下:
import os,sys
import shutil
cur_file = os.path.basename(sys.argv[0])
dir_content = [x for x in os.listdir(".") if x != cur_file]
for f in dir_content:
if os.path.isdir(f):
shutil.rmtree(f)
else:
os.remove(f)
</div>
希望本文所述对大家的Python程序设计有所帮助。
</div>
