0

我有两个谷歌驱动器帐户。如何知道第一个帐户中的目录是否=第二个帐户中的目录?

两个目录的定义相同:文件内容相同,树层次结构相同。

4

1 回答 1

0

存在的问题:

    1. populate_tree_recursively_dict如果您的谷歌驱动器很大,则需要运行 > 2 天
    1. 如果运行时发生错误,您将一无所获
    1. 假设相同的名称将意味着相同的文件或相同的文件夹
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

def get_folder_id(root_folder_id, root_folder_title):
    file_list = get_children(root_folder_id)
    for file in file_list:
        if(file['title'] == root_folder_title):
            return file['id']
def get_children(root_folder_id):
    str = "\'" + root_folder_id + "\'" + " in parents and trashed=false"
    file_list = drive.ListFile({'q': str}).GetList()
    return file_list
def populate_tree_recursively_dict(tree,parent_id)
    if True: 
        print("now add tree")
        children = get_children(parent_id)

        if children:
            print("all children get, len",len(children))
            tree["child"]=[]
            for i in children:

                treeGetFromChild=populate_tree_recursively_dict({"title":i["title"]},i["id"])
                tree["child"].append(treeGetFromChild)
        else:
            print("no children")
        return tree


# first time auth to account A
gauth = GoogleAuth() 
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

root_folder_title = "folderNameInAccountA"  
root_folder_id = get_folder_id("root", root_folder_title)
preservedict={"heyhey":"root"}
a=populate_tree_recursively_dict(preservedict,root_folder_id)

# first time auth to account B
gauth = GoogleAuth() 
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

root_folder_title = "folderNameInAccountB"  
root_folder_id = get_folder_id("root", root_folder_title)
preservedict={"heyhey":"root"}
b=populate_tree_recursively_dict(preservedict,root_folder_id)

# compare 
import deepdiff
deepdiff.DeepDiff(a, b, ignore_order=True)
于 2021-07-09T09:18:14.293 回答