python源代码(create,huafen,doc)

import os
path = 'file_create'	#设置创建后文件夹存放的位置
for i in range(102):	#这里创建102个文件夹
	# *定义一个变量判断文件是否存在,path指代路径,str(i)指代文件夹的名字*
    isExists = os.path.exists(path+str(i))
    if not isExists:						#判断如果文件不存在,则创建
        os.makedirs(str(i))
        print("%s 目录创建成功"%i)
    else:
        print("%s 目录已经存在"%i)
        continue			#如果文件不存在,则继续上述操作,直到循环结束


file = open('im_valid.txt','r')
#outfile = open('outtest','w')
line = '1'
while line != '':
    line = str(file.readline())
    write = open(line[20:-1]+'.txt', 'a') #以追加的方式创建以数字为名的文本文件
    write.write(line[4:19]+'\n') #写入行
    write.close()
    print(line)#[20:-1]) 



file.close()
import os  # os是用来切换路径和创建文件夹的。
from shutil import copy  # shutil 是用来复制黏贴文件的


file_path = r'C:\Users\deep learning\.keras\file_create\jpg'  # 想拆分的文件夹所在路径,也就是一大堆文件所在的路径

line = '1'

for i in range(102):
    file = open(str(i)+'.txt', 'r')
    while line != '':
        print(line)
        line = str(file.readline()).replace('\n','')
        if line != '1':
            from_path = os.path.join(file_path, line)
            to_path = 'C:\\Users\\deep learning\\.keras\\file_create'+'\\'+str(i)
            print(from_path, to_path)
            try:
                copy(from_path, to_path)
            except:
                pass
    file.close()
    line = '1'

你可能感兴趣的:(python,开发语言)