Python

Google Dirve API フォルダ内のファイル・サブフォルダを取得する方法【Python】

Python × Google Google Drive APIを使ってGoogleドライブの特定フォルダ内に存在する、フォルダ、ファイルの一覧を取得する方法。

#importやGoogleのOAuth2.0認証の手順は省略

def sample01(arg_folder_id):
    res = service.files().list(
        q = f"'{arg_folder_id}' in parents",
        fields="nextPageToken, files(id, name)"
        ).execute()

#これでresにarg_folder_idに含まれるフォルダとファイルの一覧が含まれています。

Google Drive のフォルダIDの調べ方は以下を参照。

▼参考文献

Files: list  |  Drive API  |  Google Developers
Search for files and folders  |  Drive API  |  Google Developers
Search for files with a specific label or field value  |  Drive API  |  Google Developers

コメント

タイトルとURLをコピーしました