1. 程式人生 > ># 此函式將指定檔案移動到指定目錄(os模組和shutil模組)

# 此函式將指定檔案移動到指定目錄(os模組和shutil模組)

import os
import shutil


def move_file(src_path, dst_path, file):
    print 'from : ',src_path
    print 'to : ',dst_path
    try:
        # cmd = 'chmod -R +x ' + src_path
        # os.popen(cmd)
        f_src = os.path.join(src_path, file)
        if not os.path.exists(dst_path):
            os.mkdir(dst_path)
        f_dst = os.path.join(dst_path, file)
        shutil.move(f_src, f_dst)
        redis.set(file, 'move_success')
    except Exception as e:
        print 'move_file ERROR: ',e
        traceback.print_exc()