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脚本,该脚本用于从源路径移动文件到目标路径,并包含了错误处理机制。通过使用os和shutil模块,脚本能检查目标路径是否存在,不存在则创建之,并执行文件移动操作。
3045

被折叠的 条评论
为什么被折叠?



