就是简单的创建十个目录,在目录下创建与目录同名的文件加上文件创建的次数

来源:互联网 发布:java程序结构分为 编辑:程序博客网 时间:2024/05/14 15:25
就是简单的创建十个目录,在目录下创建与目录同名的文件加上文件创建的次数#coding=utf8 import os dirpath ='D:\\untitled\\excel\\' for i in range(10):    newfile =(dirpath + 'createfile'+ '%d') %i    dirfile = os.path.abspath(newfile)    new_dir =dirfile.split('\\')[-1]    create_file = ("create_file" + "%d" + ".txt") %i    new_file = (dirfile +'\\'+ create_file)    new_filename =new_file.split('\\')[-1]    if  not os.path.isdir(dirfile):        print new_file  #文件        os.mkdir(dirfile)        print "%s 目录创建成功" %new_dir    else :        print "%s 文件夹已存在,跳过" %new_dir    if not os.path.isfile(new_file):            with open(new_file,'w+') as test:                test.write("")                print "%s 文件创建成功" %new_filename    else :            print "%s 文件已存在,跳过" %new_filename**`重点内容`** ```
0 0