今天被同步盤搞得焦頭爛額。
辛苦碼的代碼(除了重要的、備份過的)都被刪掉了……
當時我就石化了。。。
隨后發(fā)現(xiàn)同步盤目錄有個delete目錄,里面還有manifest.xml,和一堆改了名的文件,
看到manifest.xml的內容時,瞬間覺得有救了,立馬開搞python
廢話不多說,直接上代碼:
#-*- coding:utf-8 -*-from xml.etree import ElementTreeimport osimport sysreload(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") 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可以在官網(wǎng)下載:https://www.python.org/downloads/
將本文件(假如叫做huifu.py)放在云同步盤的根目錄下,比如云同步盤在“d:/baiduyun/”,那么文件應該在“d:/baiduyun/”下,最終是這樣的“d:/baiduyun/huifu.py”
千萬不要輕易從百度云上刪除已經(jīng)上傳的文件啊!血淚教訓。。。
以上這篇恢復百度云盤本地誤刪的文件腳本(簡單方法)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點
疑難解答
圖片精選