Restore the File Script accidentally deleted from Baidu cloud disk (simple method ).

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.