# -*- coding: utf-8 -*- # !/usr/bin/env python import os, sys import shutil from os.path import abspath, join PROJECT_ROOT = abspath(os.path.split(os.path.realpath(__file__))[0] + "/..") sys.path.insert(0, PROJECT_ROOT) def touch(file_name): if os.path.exists(file_name): print("file exist! {}".format(file_name)) else: print("creating %s" % file_name) fid = open(file_name, 'w') fid.close() backup_path = 'E://todo//2019' dest_path = 'e://images' with open('e://images//www.washpayer.com-error.log', 'r') as f: all = f.read().split() for item in all: back_file = os.path.abspath(os.path.join(backup_path, item)) tokens = item.split('/') dest_dir = os.path.abspath(os.path.join(dest_path, tokens[0])) dest_file = os.path.abspath(os.path.join(dest_path, item)) if not os.path.exists(dest_dir): os.makedirs(dest_dir) if os.path.exists(back_file): try: shutil.copyfile(back_file, dest_file) except Exception as e: print('copy failure.') else: touch(dest_file)