在实际工作中,我们会用到python复制文件到另外一个文件夹。上代码:
import os
import shutil
def copyfile(file_path, back_dir): # 复制函数
if not os.path.isfile(file_path):
print("%s not exist!" % (file_path))
else:
fpath, fname = os.path.split(file_path) # 分离文件名和路径
if not os.path.exists(back_dir):
os.makedirs(back_dir) # 创建路径
shutil.copy(file_path, back_dir + fname) # 复制文件
print("copy %s -> %s" % (file_path, back_dir + fname))
# if __name__ == '__main__':
# file_path = r'/www/wwwroot/xray_scan/scan_result/https_66_220_31_47.html'
# back_dir = r'/www/wwwroot/xray_scan/scan_result_back/'
# copyfile(file_path, back_dir)免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理