How to find the sub folder id in google drive using pydrive in python

自古美人都是妖i 提交于 2020-08-11 01:10:12

问题


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

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

回答1:


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

Answer:

Unfortunately, this is not possible.

More Information:

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

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.

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!



来源:https://stackoverflow.com/questions/62092499/how-to-find-the-sub-folder-id-in-google-drive-using-pydrive-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!