Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of file in a folder/ DRIVE API PyDRIVE

I can't change folder and view what's inside.

drive = GoogleDrive(gauth)
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
print("File %s\n\n",(file1))

I used the following code:

file_list = drive.ListFile({'q': "'/test1' in parents and trashed=false"}).GetList()

but it doesn't work. There's the documentation of the functions I used: https://developers.google.com/drive/v3/reference/files/list

like image 397
simone989 Avatar asked Oct 24 '16 17:10

simone989


People also ask

How do I get a list of files in Google Drive?

Create a new Google Sheets spreadsheet or open an existing spreadsheet where you want the list saved. Here's a tip: You can quickly create a new Google Sheets spreadsheet using https://spreadsheet.new. Create a sheet in the spreadsheet called "Files". The list of files will be written to the sheet.

Is PyDrive deprecated?

Deprecated. This project is deprecated and no longer maintained.


1 Answers

You have to insert the folder ID instead of its path. You can get the ID in different ways:

  1. Using PyDrive: If you list all folders in root, you can list all folder names with their respective IDs.
  2. Using the Web interface: Navigate into the folder you want to get the ID from. Look at the URL, it has this format: drive.google.com/drive/u/0/folders/<folder ID>

Now insert the folder ID into the request.

file_list = drive.ListFile({'q': "'<folder ID>' in parents and trashed=false"}).GetList()

FYI: Google Drive is a tag-based (also called semantic) file system, which, for example, allows a file to be in several places at the same time (just by adding IDs of folders to the file's parents property).

like image 81
Robin Nabel Avatar answered Nov 02 '22 23:11

Robin Nabel