python 复制并重命名文件_Python_复制文件并重新命名

1 #-*- coding:utf-8 -*-

2

# 引用 os 和 sys 两个模块

3 importos4 importsys5

# 定义 n 作为次数,显示 a.txt 文件内的内容

6 n =07 h1 = open("a.txt").read()8 printh1

# 这里做了一个循环,循环复制文件并修改文件名:9 whileTrue: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" %n19 printW_file20 n += 1

21 printn22 W = open(W_file,'w')23 W.write(str(R1))24 if n == 30:25 break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值