小米手机备份,但缺少了个descript文件,找到一个生成该文件的脚本,但不知道如何运行
代码如下
#coding:utf-8
import os
def bak_files_path(dir):
outputFile = dir + "/descript.xml"
f = open(outputFile, 'w', encoding="utf-8")
content = ""
for root, dirs, files in os.walk(dir):
print("当前操作目录: ", root)
for file in files:
try:
content += "<package><packageName>%s</packageName><feature>-1</feature><bakFile>%s</bakFile><bakType>2</bakType><pkgSize>53026614</pkgSize><sdSize>0</sdSize><state>1</state><completedSize>53025792</completedSize><error>0</error><progType>0</progType><bakFileSize>0</bakFileSize><transingCompletedSize>0</transingCompletedSize><transingTotalSize>0</transingTotalSize><transingSdCompletedSize>0</transingSdCompletedSize><sectionSize>0</sectionSize><sendingIndex>0</sendingIndex></package>" % (file[file.index("(") + 1: file.index(")")], file)
finally:
# 跳过不规则文件
continue
template = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><MIUI-backup><jsonMsg></jsonMsg><bakVersion>2</bakVersion><brState>3</brState><autoBackup>false</autoBackup><device>cmi</device><miuiVersion>V12.5.3.0.RJACNXM</miuiVersion><date>1621923274164</date><size>61445281</size><storageLeft>192279056384</storageLeft><supportReconnect>true</supportReconnect><autoRetransferCnt>0</autoRetransferCnt><transRealCompletedSize>0</transRealCompletedSize><packages>%s</packages><filesModifyTime /></MIUI-backup>"%(content)
f.write(template)
f.close()
# 只操作当前目录,不操作子目录
print("descript.xml 生成完毕 ->", outputFile)
return
# 在此处修改目录
bak_files_path("E:\20211015_124237")
bak_files_path("E:\20211015_124237"),这里路径写法改一下,改成:bak_files_path(r"E:\20211015_124237"),或者:bak_files_path("E:/20211015_124237"),路径中有转义符会被转义。
出现了filenot found error咋办