python - # 此函数将指定文件移动到指定目录(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()

你可能感兴趣的:(python,python,移动文件,shutil,os,path)