List of file in a folder/ DRIVE API PyDRIVE

淺唱寂寞╮ 提交于 2019-12-07 01:06:12

问题


I can't change folder and view what's inside.

drive = GoogleDrive(gauth)
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
print("File %s\n\n",(file1))

I used the following code:

file_list = drive.ListFile({'q': "'/test1' in parents and trashed=false"}).GetList()

but it doesn't work. There's the documentation of the functions I used: https://developers.google.com/drive/v3/reference/files/list


回答1:


You have to insert the folder ID instead of its path. You can get the ID in different ways:

  1. Using PyDrive: If you list all folders in root, you can list all folder names with their respective IDs.
  2. Using the Web interface: Navigate into the folder you want to get the ID from. Look at the URL, it has this format: drive.google.com/drive/u/0/folders/<folder ID>

Now insert the folder ID into the request.

file_list = drive.ListFile({'q': "'<folder ID>' in parents and trashed=false"}).GetList()

FYI: Google Drive is a tag-based (also called semantic) file system, which, for example, allows a file to be in several places at the same time (just by adding IDs of folders to the file's parents property).




回答2:


I think https://stackoverflow.com/a/47764444/1003629 solves a similar problem and should help you. The problem here is permissions to the required folders, which is by default only the root.



来源:https://stackoverflow.com/questions/40224559/list-of-file-in-a-folder-drive-api-pydrive

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