Here under
"Update file metadata" it shows how to change the title from a created file. I'm looking for how to change the title if I know the id or key. Or is there a way to do it in gspread
?
Asked
Active
Viewed 2,359 times
2 Answers
4
You can also do this directly with PyDrive. CreateFile() only creates a local Python object to represent the state of a new or existing file
# CreateFile() can be called with an existing id.
file1 = drive.CreateFile({'id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'})
file1['title'] = '<new title>' # Change title.
file1.Upload() # Upload new title.

jason
- 3,811
- 18
- 92
- 147

Robin Nabel
- 2,170
- 1
- 21
- 26
-
Ok. You want to rename an existing file, one for which you have only the id. If this is correct, then the above code will do /exactly/ the same as your code, just in a consistent way, using PyDrive. CreateFile() only creates a local Python object to represent the state of a new or existing file. If you call FetchMetadata() after `file1 = ...` then you can also extract the current name. – Robin Nabel Feb 07 '17 at 15:34
2
i found it
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
id='xxxxxxxxxxxxxxxxxxxxxxxx'
a=drive.auth.service.files().get(fileId=id).execute()
a['title']="new title"
update=drive.auth.service.files().update(fileId=id,body=a).execute()

jason
- 3,811
- 18
- 92
- 147