File: using_folders.py

package info (click to toggle)
pydrive2 1.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 496 kB
  • sloc: python: 3,601; makefile: 8
file content (30 lines) | stat: -rw-r--r-- 792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

# Create folder.
folder_metadata = {
    "title": "<your folder name here>",
    # The mimetype defines this new file as a folder, so don't change this.
    "mimeType": "application/vnd.google-apps.folder",
}
folder = drive.CreateFile(folder_metadata)
folder.Upload()

# Get folder info and print to screen.
folder_title = folder["title"]
folder_id = folder["id"]
print("title: %s, id: %s" % (folder_title, folder_id))

# Upload file to folder.
f = drive.CreateFile(
    {"parents": [{"kind": "drive#fileLink", "id": folder_id}]}
)

# Make sure to add the path to the file to upload below.
f.SetContentFile("<file path here>")
f.Upload()