My Google Drive looks something like this:
picture1.jpg
song1.mp3
a/b/file1.txt
a/b/file2.txt
a/b/file3.jpg
a/b/file4.m4a
a/b/...
I want to use PyDrive to download every file in folder "b". After looking at the documentation and checking StackOverflow, I still cannot figure out how to do this. How would I download all of the files in folder "b" (which is contained in folder "a") using PyDrive. Also, in case it's relevant please note that folder "b" contains thousands of files.
Download a file to a custom folder: To download a file to a specific folder, pass it the --directory-prefix or -P flag, followed by the destination folder. Interestingly, when the path to the folder doesn't exist, Wget will create it.
I figured it out. Basically you need to use the file id to list or download a folder's contents.
Assuming that file_list is the root directory:
for file1 in file_list:
if file1['title'] == '[name_of_target_folder]':
folder_id = file1['id']
Then
> folder_id
> 'WIU1xyz19g83abcdefg'
(for example)
get every file in 'folder':
file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
download every file in 'folder':
for i, file1 in enumerate(sorted(file_list, key = lambda x: x['title']), start=1):
print('Downloading {} from GDrive ({}/{})'.format(file1['title'], i, len(file_list)))
file1.GetContentFile(file1['title'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With