Restore the File Script accidentally deleted from Baidu cloud disk (simple method ).
The synchronization disk was overwhelmed today.
Code with hard code (except important and backed up) has been deleted ......
At that time, I became Petrochemical...
Then we found that the synchronization disk Directory had a delete Directory, which contains manifest. xml and a bunch of files with names changed,
When I saw the manifest. xml content, I instantly felt it was saved. I immediately started python.
If you don't talk much about it, go directly to the Code:
#-*-Coding: UTF-8-*-from xml. etree import ElementTreeimport osimport sysreload (sys) sys. setdefaultencoding ("UTF-8") def convertfile (cachePath, orgPath): '''restore file' '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. exi Sts (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): '''read xml file ''' 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 __': ''' place the file in the root directory of the cloud synchronization disk and change mani_file to the manifest file to be restored ''' mani_file = ". \\. baohe. cache \\. delete \ 20140412 \ manifest. xml "read_xml (open (mani_file ). read ())
This file is normal under Python2.7.6, and 3.4 seems to be faulty (perspiration)
Python can be downloaded on the official site: https://www.python.org/downloads/
This file (for exampleHuifu. pyIn the root directory of the cloud synchronization disk.: \ Baiduyun \", The file should be in the"D: \ baiduyun \In the end,"D: \ baiduyun \ huifu. py"
Never delete uploaded files from Baidu cloud easily! Tears lesson...
The above file script for restoring the accidental deletion of Baidu cloud disk (simple method) is all the content shared by Alibaba Cloud xiaobian. I hope it can be used as a reference and support for the customer's home.