Search code examples
pythondirectorypydrive

is there a way to upload an entire folder to google drive using pydrive?


I'm doing a python script which periodically upload a folder to Google Drive, but got stuck when I had to load subfolders. Is there any way to upload an entire folder?

Maybe with a loop but I have no idea how to do it.

Below is an example of a folder to upload:

root\
root\image.png
root\Folder1\text.txt
root\Folder1\music.mp3
root\Folder2\MyFolder\homeworks.txt
root\Folder2\Something\something.txt

I'm using PyDrive.


Solution

  • A simpler workaround is to just zip the file:

    shutil.make_archive('data', 'zip', 'output')
    file = drive.CreateFile({'title': 'data.zip'})
    file.SetContentFile('data.zip')
    file.Upload()