Accessing folders, subfolders and subfiles using PyDrive (Python)

It requires iteration with list of files. Based on this, the code fetches the title of file and url link of the each files with in the folder. The code is adjustable to get the specific folder by supplying the id of the folder such as ListFolder('id'). The given below example is querying the root

# -*- coding: utf-8 -*-
from pydrive.auth import GoogleAuth
from import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication

#Make GoogleDrive instance with Authenticated GoogleAuth instance
drive = GoogleDrive(gauth)

def ListFolder(parent):
  file_list = drive.ListFile({'q': "'%s' in parents and trashed=false" % parent}).GetList()
  for f in file_list:
    if f['mimeType']=='application/': # if folder
  return filelist


Your code is absolutely correct. But with the default settings of Pydrive , you have access to only the root level files and folders. Changing oauth_scope in settings.yaml file fixes this issue.

client_config_backend: settings
client_id: XXX
client_secret: XXXX

save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json

get_refresh_token: True