import os
L=[]
def delete_file(file):
if os.path.isdir(file):
files=os.listdir(file)
for x in files:
x=os.path.join(file,x)
if os.path.isfile(x):
print( os.path.split(x)[1])
L.append(os.path.split(x)[1])
# os.remove(x)
elif os.path.isdir(x) :
print(os.path.split(x)[1])
L.append(os.path.split(x)[1])
# if len(os.listdir(x))!=0:
delete_file(x)
else:
L.append(os.path.split(file))
ll=delete_file(r‘E:\\ALL_IN\python脚本\a‘)
print(‘-------------------‘)
print(L)
原文:https://www.cnblogs.com/shiyishou/p/14743322.html