文件夹中的文件列表/DRIVE API PyDRIVE [英] List of file in a folder/ DRIVE API PyDRIVE
问题描述
我无法更改文件夹并查看其中的内容.
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))
我使用了以下代码:
file_list = drive.ListFile({'q': "'/test1' in parents and trashed=false"}).GetList()
但是它不起作用. 有我使用的功能的文档: https://developers.google.com/驱动器/v3/参考/文件/列表
but it doesn't work. There's the documentation of the functions I used: https://developers.google.com/drive/v3/reference/files/list
推荐答案
您必须插入文件夹ID而不是其路径.您可以通过不同的方式获取ID:
You have to insert the folder ID instead of its path. You can get the ID in different ways:
- 使用PyDrive:如果您以root身份列出所有文件夹,则可以列出所有文件夹名称及其各自的ID.
- 使用Web界面:导航至要从中获取ID的文件夹.查看URL,它具有以下格式:
drive.google.com/drive/u/0/folders/<folder ID>
现在将文件夹ID插入请求中.
Now insert the folder ID into the request.
file_list = drive.ListFile({'q': "'<folder ID>' in parents and trashed=false"}).GetList()
仅供参考:Google云端硬盘是基于标签(也称为语义)的文件系统,例如,它允许文件同时位于多个位置(只需将文件夹ID添加到文件的parents
财产).
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).
这篇关于文件夹中的文件列表/DRIVE API PyDRIVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!