Python | 用python代碼導(dǎo)出百度網(wǎng)盤文件目錄

用python代碼導(dǎo)出百度網(wǎng)盤文件目錄

PyCharm 創(chuàng)建項(xiàng)目

一、用PyCharm 創(chuàng)建項(xiàng)目

新建一個(gè)py文件,baiduexport.py,貼入以下代碼:

__title__ = ''
__author__ = 'jungle'
__mtime__ = '2019-01-18'
"""
#!/usr/bin/env python3

# -*- coding:utf-8 -*-


from tkinter import *

from tkinter.filedialog import askopenfilename

from tkinter.filedialog import asksaveasfilename

from tkinter.ttk import *

import sqlite3


def select_db_file():
    db_file = askopenfilename(title="請選擇BaiduYunCacheFileV0.db文件", filetypes=[('db', '*.db')])

    db.set(db_file)


def select_save_file():
    save_file = asksaveasfilename(filetypes=[('文件', '*.txt')])

    f.set(save_file + ".txt")


def write_file(file_dict, f, item, gap=""):
    if item == "/":

        f.write("━" + "/" + "\n")

        for i in file_dict["/"]:

            f.write("┣" + "━" + i + "\n")

            i = item + i + "/"

            if i in file_dict:
                write_file(file_dict, f, i, gap="┣━")

    else:

        gap = "┃  " + gap

        for i in file_dict[item]:

            f.write(gap + i + "\n")

            i = item + i + "/"

            if i in file_dict:
                write_file(file_dict, f, i, gap)


def create_baiduyun_filelist():
    file_dict = {}

    conn = sqlite3.connect(db.get())

    cursor = conn.cursor()

    cursor.execute("select * from cache_file")

    while True:

        value = cursor.fetchone()

        if not value:
            break

        path = value[2]

        name = value[3]

        size = value[4]

        isdir = value[6]

        if path not in file_dict:

            file_dict[path] = []

            file_dict[path].append(name)

        else:

            file_dict[path].append(name)

    with open(f.get(), "w", encoding='utf-8') as fp:

        write_file(file_dict, fp, "/")


root = Tk()

root.title('百度云文件列表生成工具')

db_select = Button(root, text=' 選擇DB文件 ', command=select_db_file)

db_select.grid(row=1, column=1, sticky=W, padx=(2, 0), pady=(2, 0))

db = StringVar()

db_path = Entry(root, width=80, textvariable=db)

db_path['state'] = 'readonly'

db_path.grid(row=1, column=2, padx=3, pady=3, sticky=W + E)

save_path = Button(root, text='選擇保存地址', command=select_save_file)

save_path.grid(row=2, column=1, sticky=W, padx=(2, 0), pady=(2, 0))

f = StringVar()

file_path = Entry(root, width=80, textvariable=f)

file_path['state'] = 'readonly'

file_path.grid(row=2, column=2, padx=3, pady=3, sticky=W + E)

create_btn = Button(root, text='生成文件列表', command=create_baiduyun_filelist)

create_btn.grid(row=3, column=1, columnspan=2, pady=(0, 2))

root.columnconfigure(2, weight=1)

root.mainloop()

二、運(yùn)行

運(yùn)行結(jié)果

三、選擇db文件目錄

選擇百度云安裝文件夾的users文件夾下的BaiduYunCacheFileV0.db這個(gè)文件。

四、設(shè)置生成的目錄文件位置

可設(shè)置到任何你找到的位置,文件為txt文本文件。


設(shè)置

五、單擊“生成文件列表”

部分目錄
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容