python中使用pydrive在Google驱动器中查找子文件

python中使用pydrive在Google驱动器中查找子文件

本文介绍了如何在python中使用pydrive在Google驱动器中查找子文件夹ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google驱动器上的目录限制如下: 在mydrive/BTP/BTP-4内部

The directory stricture on google drive is as follows: Inside mydrive/BTP/BTP-4

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

I need to get the folder ID for BTP-4 so that I can transfer a specific file from the folder. How do I do it??

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

推荐答案

答案:

很遗憾,这是不可能的.

Google云端硬盘支持在同一位置创建多个具有相同名称的文件或文件夹:

Google Drive supports creating multiple files or folders with the same name in the same location:

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

As a result of this, in some cases, providing a file path isn't enough to identify a file or folder uniquiely - in this case mydrive/Parent folder/Child folder/Child doc points to two different files, and mydrive/Parent folder/Child folder/Child folder points to five different folders.

您必须直接搜索具有其ID的文件夹,或者要获取文件夹/文件的ID,您必须像以前已经在文件夹中递归搜索子项.

You have to either directly search for the folder with its ID, or to get a folder/file's ID you have to search for children recursively through the folders like you are already doing.

我知道这通常是个坏消息,但我希望这对您有帮助!

I know this is generally bad news, but I hope this is helpful to you!

这篇关于如何在python中使用pydrive在Google驱动器中查找子文件夹ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:55