Cannot update file metadata
I am attempting to update the metadata of a file for which I have the fileID. My code is identical to that in the documentation:
f = drive.CreateFile({'id': filesContained['id']})
f['title'] = filename
print(f['title'])
f.Upload()
print(f['title'])
where the filesContained['id'] is the correct ID, as I have verified. When I execute this code (in the context of my program), it will print the desired name of my file, but following the upload, the second print statement prints the original name of the file, and indeed the file is seen to not have its title changed in the google drive. What am I doing wrong?
Thank you for reporting this. Have you checked whether the file's name is changed on Google Drive? The fact that the title value is reset would make some sense if the change was rejected for some reason. Are any errors raised?
If changes are successful remotely and you need a quick fix, you can try the code below:
f = drive.CreateFile({'id': filesContained['id']})
f.FetchMetadata()
print(f['title'])
Thanks for getting back to me.
There are no errors raised, and the title of the file is not changed remotely. I've pretty much attempted this every way I can think of, with both files and folder, with python 2 and 3, and I'm not having any luck. Is this a problem unique to me?
I am facing the same trouble
Facing the same problem. Files get updated but their names remain the same.
I found a fix to this issue, first run a request to the file object, then make the changes.
f = drive.CreateFile({'id': filesContained['id']})
f_old_title = f['title']
f['title'] = 'New Title'
f.Upload()
I agree with @swearingbird method (tried on Python 3.8, Windows 7, I could rename files and folders).
For some reason, the assignation of a new value to f['title'] only works if its old value has been previously read.
Also, @RNabel f.FetchMetadata() code above raises an error, as reported in PyDrive2 fork issues #91 and #103