记录使用python匹配文件名做文件复制

import os,shutil


def cp_file(source_directory, target_directory):
  shutil.copy(source_directory, target_directory)

 

def get_path_file():
  with open('2.txt') as fd:
    file_name = fd.readlines()
    for i in file_name:
      sour_path = i.strip()
      #local_path = os.path.join("/tmp","1","%s") %(i.strip().split('/')[4])
      #local_path = i.strip().split('/')[4]
      local_path = '/tmp/1/'
      cp_file(sour_path,local_path)
      print 'ok'

get_path_file()

 

posted @ 2017-03-13 09:17  eguotangseng  阅读(1238)  评论(0编辑  收藏  举报