源码如下:
#用于判断文件路径是否存在和创建文件夹
import os
#用于删除文件夹目录
import shutil
path = 'c:\\test\\'
if os.path.exists(path):
shutil.rmtree(path)
os.mkdir(path)
for i in range(5):
os.mkdir(path+str(i+1))
li = []
for i in range(1,6):
li.append(path+str(i)+'.txt')
for i in range(5):
with open(li[i], 'w') as f:
pass
print(os.listdir(path))
运行结果:
['1', '1.txt', '2', '2.txt', '3', '3.txt', '4', '4.txt', '5', '5.txt']