如何使用 Python 中的 pydrive 在 Google Drive 中找到子文件夹 ID?

How to find the sub folder id in Google Drive using pydrive in Python?

Google驱动器的目录结构如下: 里面 mydrive/BTP/BTP-4

我需要获取 BTP-4 的文件夹 ID,以便我可以从该文件夹传输特定文件。我该怎么做?

fileList = GoogleDrive(self.driveConn).ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file in fileList:
    if (file['title'] == "BTP-4"):
        fileID = file['id']
        print(remoteFile, fileID)
        return fileID

Will be able to give path like /MyDrive/BTP/BTP-4 and filename as "test.csv" and then directly download the file?

答案:

很遗憾,这是不可能的。

更多信息:

Google Drive支持在同一位置创建多个同名文件或文件夹:

因此,在某些情况下,提供文件路径不足以唯一地识别文件或文件夹 - 在这种情况下,mydrive/Parent folder/Child folder/Child doc 指向两个不同的文件,mydrive/Parent folder/Child folder/Child folder 指向五个不同的文件夹。

您必须直接搜索具有 ID 的文件夹,或者要获得 folder/file 的 ID,您必须像您已经在做的那样递归地搜索子文件夹。