Python 谷歌硬盘上的递归列表文件问题
我试图递归地列出特定google drive文件夹中的所有文件和文件夹Python 谷歌硬盘上的递归列表文件问题,python,google-drive-api,Python,Google Drive Api,我试图递归地列出特定google drive文件夹中的所有文件和文件夹 def list_file(parent): result = service.files().list(q= "'%s' in parents and trashed=false" % parent).execute(http=decorator.http()) tasks = result.get('items', []) for f in tasks: if f['mimeType'] == 'a
def list_file(parent):
result = service.files().list(q= "'%s' in parents and trashed=false" % parent).execute(http=decorator.http())
tasks = result.get('items', [])
for f in tasks:
if f['mimeType'] == 'application/vnd.google-apps.folder':
list_file(f['id'])
return tasks
tasks = list_file('the specific folder ID')
问题是,它只返回直接位于特定文件夹ID下的文件和文件夹列表,而不返回子文件夹和子文件夹中的文件
有人知道我应该如何修改代码以使其正常工作吗?谢谢
或者,有没有更好的方法来使用其API列出google drive中特定文件夹下的所有文件和子文件夹的文件?如果有人能分享代码那就太好了
提前感谢。我不是python专家,但我建议您在某个时候将对
列表文件的内部调用的结果添加到任务
结果变量中。如果更改行:
list_file(f['id'])
到
tasks.extend(list_file(f['id']))