我想从以下路径搜索文件夹内的文件,即文件:test-download / abc / test.txt。但是当尝试使用Google API时,它给了我单独的文件和文件夹名称,但是我怎么知道'test.txt'来自'test-download / abc'。尝试以下代码:
service = discovery.build('drive', 'v3', http=creds.authorize(Http()))
page_token = None
while True:
response = service.files().list(q="mimeType='application/vnd.google-apps.folder' or mimeType='text/plain'",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
print(response)
for file in response.get('files', []):
# Process change
print('Found file: %s (%s)' % (file.get('name'), file.get('id')))
page_token = response.get('nextPageToken', None)
if page_token is None:
break
例如,您可以使用q query指定父文件夹的ID
response = service.files().list(q="'PASTE HERE THE PARENT FOLDER ID' in parents",
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()