googlearchive / PyDrive

Google Drive API Python wrapper library
Other
1.31k stars 272 forks source link

How do I get the ID of a specifically named folder? #210

Open Paulbraker opened 4 years ago

Paulbraker commented 4 years ago

Ok so when the specific folder is not created I can create it, but If it exists I need the ID of the folder to work with it. This is my code so far:

f = drive.ListFile({"q": "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()
    AllFolders = []
    for folder in f:
        AllFolders.append(folder['title'])

    if "Pythontesting1" not in AllFolders:
            folder_metadata = {'title' : 'Pythontesting1', 'mimeType' : 'application/vnd.google-apps.folder'}
            folder = drive.CreateFile(folder_metadata)
            folder.Upload()
    else:
        #What do I put here?