encode是编码
例如 name.encode(“GB2312”),表示将字符串name以GB2312编码。
decode是解码
例如 name.decode(“GB2312”),表示将字符串name以GB2312解码。
按行读取TXT里的文件名,把文件移到指定的路径里。
# -*- coding: utf-8 -*-
import threading
import time
import os,sys
import shutil
from tube import progressbar
from os.path import join, getsize
from shutil import Error
from shutil import copystat
from shutil import copy2
#oldpath,newpath,thefile
n=0
for line in open('C:\Users\Administrator\Desktop\move.txt'):
n+=1
i=0
for line in open('C:\Users\Administrator\Desktop\move.txt'):
i+=1
line=line.strip()
path=join('C:\Users\Administrator\Desktop\ZDZ_file',line) #把路径和文件名连接起来
f_path=unicode(path, "utf-8") #把文件名用utf-8编码
try:
shutil.move(f_path,'C:\Users\Administrator\Desktop\point')
progressbar(i,n)
except:
print(line+'/n')
print("以上文件传输失败!")
from __future__ import division
import math
import sys
def progressbar(cur,total):
percent = '{:.2%}'.format(cur / total)
sys.stdout.write('\r')
sys.stdout.write('[%-50s] %s' % ( '=' * int(math.floor(cur * 50 /total)),percent))
sys.stdout.write('\n')
sys.stdout.flush()
# if cur == total:
# sys.stdout.write('\n')
if __name__ == '__main__':
file_size = 102400000
size = 1024
while file_size > 0:
progressbar(size*10/file_size,10)
file_size -= 1024
#for i in range(11):
# progressbar(i,10)
# time.sleep(1)