Python复制文件到另外一个文件夹
在实际工作中,我们会用到python复制文件到另外一个文件夹。上代码:
importos importshutil defcopyfile(file_path,back_dir):#复制函数 ifnotos.path.isfile(file_path): print("%snotexist!"%(file_path)) else: fpath,fname=os.path.split(file_path)#分离文件名和路径 ifnotos.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)
以上就是关于“在Python中怎样复制文件并进行移动操作”的介绍了,感谢各位的阅读,希望这篇文章能帮助大家解决问题。如果想要了解更多知识,欢迎关注恒创科技,小编每天都会为大家更新不同的知识。