订购在 pydrive 中列出 child 的结果
Order the result for listing child in pydrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
def get_children(root_folder_id):
str = "\'" + root_folder_id + "\'" + " in parents and trashed=false"
file_list = drive.ListFile({'q': str}).GetList()
return file_list
我们能否以某种方式强制对文件列表进行排序(按字母顺序、最后修改日期等)
您可以添加 orderBy
作为文件列表功能的 optional parameters。
顺序
- 一个 comma-separated 排序键列表。
- 有效键是
'createdDate', 'folder', 'lastViewedByMeDate', 'modifiedByMeDate', 'modifiedDate', 'quotaBytesUsed', 'recency', 'sharedWithMeDate', 'starred', 'title', and 'title_natural'
。
- 每个键默认按升序排序,但可以使用
'desc'
修饰符反转。
用法示例:
?orderBy=文件夹,修改日期描述,标题。请注意,对于拥有大约 100 万个文件的用户,在其中请求的排序顺序被忽略的情况下存在当前限制。
#Order based on modified date in descending order
drive.ListFile({'orderBy': 'modifiedDate desc'}).GetList()
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
def get_children(root_folder_id):
str = "\'" + root_folder_id + "\'" + " in parents and trashed=false"
file_list = drive.ListFile({'q': str}).GetList()
return file_list
我们能否以某种方式强制对文件列表进行排序(按字母顺序、最后修改日期等)
您可以添加 orderBy
作为文件列表功能的 optional parameters。
顺序
- 一个 comma-separated 排序键列表。
- 有效键是
'createdDate', 'folder', 'lastViewedByMeDate', 'modifiedByMeDate', 'modifiedDate', 'quotaBytesUsed', 'recency', 'sharedWithMeDate', 'starred', 'title', and 'title_natural'
。 - 每个键默认按升序排序,但可以使用
'desc'
修饰符反转。
用法示例: ?orderBy=文件夹,修改日期描述,标题。请注意,对于拥有大约 100 万个文件的用户,在其中请求的排序顺序被忽略的情况下存在当前限制。
#Order based on modified date in descending order
drive.ListFile({'orderBy': 'modifiedDate desc'}).GetList()