批量对文件夹进行操作
1、删除指定文件夹:
import os
import shutil
'''
删除指定文件夹
'''
path = 'D:/python/test/test3'
ff = os.listdir(path)
for f in ff:
jia = [path+'/'+f]
for ji in jia:
if ji.split('/')[-1] == 'a':
shutil.rmtree(ji) #删除文件夹
2、保留指定文件夹
import os
import shutil
path = 'D:/python/test/test3'
ff = os.listdir(path)
'''
保留指定文件夹
'''
for f in ff:
jia = [path+'/'+f]
for ji in jia:
if ji.split('/')[-1] == 'b':
pass
elif ji.split('/')[-1] == 'hfh':
pass
else:
shutil.rmtree(ji) #删除文件夹