码迷,mamicode.com
首页 > 其他好文 > 详细

文件Move操作

时间:2014-06-25 23:22:26      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:class   blog   文件   os   name   代码   

#coding = utf-8
import  os

str1 = ‘d:/v3/‘
str2 = ‘d:/v3/‘





fobj = open(‘D:/V3/txt/1.txt‘,‘rb‘)
line = fobj.readline()
while line:
    if(line.find(‘a‘) > 0):
        strsha1 = line.split(‘\\‘)
        strsha1 = strsha1[-1]
       # print str1+strsha1
        os.rename(line, str1+strsha1)
    elif(line.find(‘b‘) > 0):
        strmd5 = line.split(‘\\‘)
        strmd5 = strmd5[-1]
       # print str2+strmd5
        os.rename(line,str2+strmd5)
    else:
        print(line)

    line = fobj.readline()

fobj.close()

  如果报error123错误,则需要添加如下代码

#sometimes filter \n or \r\n
line = line.strip(‘\r\n‘)

  

文件Move操作,布布扣,bubuko.com

文件Move操作

标签:class   blog   文件   os   name   代码   

原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/3804372.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!