shareplum icon indicating copy to clipboard operation
shareplum copied to clipboard

getfile() no local file

Open TomHynes opened this issue 5 years ago • 3 comments
trafficstars

Using shareplum to download files and manipulate locally. It's authenticating and I can delete files successfully. Not sure where files are downloading to when running folder.get_file('source.txt')

TomHynes avatar Jul 13 '20 15:07 TomHynes

I am having the same problem. If you solve this problem please let me know. Thanks!

junkmail7152 avatar Jul 15 '20 01:07 junkmail7152

get_file() returns the contents of the file, so you want to do file_contents = folder.get_file('source.txt') then write file_contents to a file handle if you want it on disk.

isaacnorman82 avatar Jul 21 '20 10:07 isaacnorman82

As @isaacnorman82 says, get_file() returns the contents.

Here is a full example that will write your remote source.txt to output.txt in your current working directory:

with open("output.txt", "w") as sink:
    file_contents = folder.get_file('source.txt')
    sink.write(file_contents)

You might want/need to specify binary mode ("wb") when handling binary files like Office documents or archives.

kannes avatar Jul 28 '20 12:07 kannes