1 # -*- coding:utf-8 -*-
2
# 引用 os 和 sys 两个模块
3 import os
4 import sys
5
# 定义 n 作为次数,显示 a.txt 文件内的内容
6 n = 0
7 h1 = open("a.txt").read()
8 print h1
# 这里做了一个循环,循环复制文件并修改文件名:
9 while True:
10
# 定义 R 为读取文件内容,检测 G:\ceshi 这个文件是否存在,如果不存在则创建一个
# 循环把读取的内容写进新建的文件内,并且循环30次
11 with (open("a.txt")) as R:
12 R1 = (R).read()
13 if not os.path.exists ("G:\\ceshi\\" ):
14 os.mkdir("G:\\ceshi\\" )
15 print "make dir success"
16 else :
17 print "dir exists"
18 W_file = "G:\\ceshi\\" + "ceshi_%s.txt" % n
19 print W_file
20 n += 1
21 print n
22 W = open(W_file,'w')
23 W.write(str(R1))
24 if n == 30:
25 break