import code
import random
import lst
import os
import os.path
#函数式编成
def create_filename():
filename_lst=[]
lst=['水果','烟酒','粮油','肉蛋','蔬菜']
code=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
for i in range(1,3001):
filename=''
#拼接文件
if i<10:
filename+='000'+str(i)
elif i<100:
filename+='00'+str(i)
elif i<1000:
filename+='0'+str(i)
else:
filename+=str(i)
#拼接类别
filename+='_'+random.choice(lst)
#拼接识别码
s=''
for j in range(9):#循环的作用是次数
s+=random.choice(code)
filename+='_'+s
filename_lst.append(filename)
return filename_lst
def create_file(filename):
with open (filename,'w')as file:
pass#可以输入文本文件内容
if __name__ == '__main__':
path='./data'
if not os.path.exists(path):
os.mkdir(path)
lst=create_filename()
for item in lst:
create_file(os.path.join(path,item)+'.txt')
print(create_filename())
批量创建文件
最新推荐文章于 2024-09-02 23:14:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)