• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

恢复百度云盘本地误删的文件脚本(简单方法)

python 搞代码 4年前 (2022-01-07) 22次浏览 已收录 0个评论

下面小编就为大家带来一篇恢复百度云盘本地误删的文件脚本(简单方法)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

今天被同步盘搞得焦头烂额。

辛苦码的代码(除了重要的、备份过的)都被删掉了……

当时我就石化了。。。

随后发现同步盘目录有个delete目录,里面还有manifest.xml,和一堆改了名的文件,

看到manifest.xml的内容时,瞬间觉得有救了,立马开搞python

废话不多说,直接上代码:

 #-*- coding:utf-8 -*- from xml.etree import ElementTree import os import sys reload(sys) sys.setdefaultencoding( "utf-8" ) def convertfile(cachePath,orgPath): '''恢复文件''' start=0; while True: index = orgPath.find('\\', start) if index == -1: break start = index + 1 orgDir=orgPath[:start] print 'orgDir:',orgDir if not os.path.exists(orgDir): os.makedirs(orgDir) if not os.path.exists(orgPath) or(os.path.exists(orgPath) and (os.path.getsize(orgPath) != os.path.getsize(cachePath))): file_in=open(cachePath, "rb") file_out=open(orgPath, "wb") file_out.write(file_in.read()) file_in.close() file_out.close() def read_xml(text): '''读xml文件''' root = ElementTree.fromstring(text) lst_node = root.getiterator("record") <div style="color:transparent">来源gaodai.ma#com搞#代!码网</div>for node in lst_node: cp=node.attrib['cachePath'] op=node.attrib['orgPath'] cp=cp.replace('~','.') op=op.replace('~','.') print cp+'->'+op convertfile(cp,op) if __name__ == '__main__': '''将本文件放在云同步盘的根目录下, 将mani_file改为需要恢复的manifest文件''' mani_file=".\\.baohe.cache\\.delete\\20140412\\manifest.xml" read_xml(open(mani_file).read())

本文件在Python2.7.6下正常,3.4貌似有问题(汗)

python可以在官网下载:https://www.python.org/downloads/

将本文件(假如叫做huifu.py)放在云同步盘的根目录下,比如云同步盘在“d:\baiduyun\”,那么文件应该在“d:\baiduyun\”下,最终是这样的“d:\baiduyun\huifu.py

千万不要轻易从百度云上删除已经上传的文件啊!血泪教训。。。

以上这篇恢复百度云盘本地误删的文件脚本(简单方法)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持gaodaima搞代码网

以上就是恢复百度云盘本地误删的文件脚本(简单方法)的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:恢复百度云盘本地误删的文件脚本(简单方法)

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址