Python3按編號創建文件夾並在文件夾下創建對應編號的txt文件

# coding=utf-8
#--author:valecalida--
import os
s = ''
flag = []
for i in s:
    flag.append(i)
print(flag)

file = 'key'
root_pass = os.getcwd()
print(root_pass)
for i in range(32):
    filename = file + str(i)
    os.mkdir(filename)			#1、創建文件夾
    os.chdir(filename)
    texts = file + str(i) + '.txt'
    f = open(texts,'w')			#2、創建txt
    f.write(flag[i])			#3、寫入內容
    f.close()
    os.chdir(root_pass)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章