1

Here's my code for a very simple program:

import os, shutil
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

source_path = r"c:/users/x/appdata/roaming/medianxl/save"
destination_path = r"c:/users/x/desktop/backup_saves"

print("Contents being backed up:")
print(os.listdir(source_path))
destination = shutil.copytree(source_path, destination_path)
print("Contents successfully backed up to:", destination_path)

print("Now uploading backup saves to Google Drive...")

auth = GoogleAuth()
auth.LocalWebserverAuth()
drive = GoogleDrive(auth)

saves = drive.CreateFile()
saves.SetContentFile(r"c:/users/x/desktop/backup_saves")
saves.Upload()

So far I am having no issues when it comes to taking the folder from the appdata location and copying it to my desktop. Where I am getting the error in my title is when I go to upload that folder and its contents on my desktop to Google Drive using pydrive.

Here's the output from the command window after running the program:

Contents being backed up:
['preferences.json', 'TSW', 'uhp_prettycolor.d2s', 'uhp_prettycolor.key', 'uhp_prettycolor.ma0', 'uhp_prettycolor.map']
Contents successfully backed up to: c:/users/x/desktop/backup_saves
Now uploading backup saves to Google Drive...
Your browser has been opened to visit:

    url here

Authentication successful.
Traceback (most recent call last):
  File "backup.py", line 21, in <module>
    saves.SetContentFile(r"c:/users/x/desktop/backup_saves")
  File "C:\Users\x\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\files.py", line 169, in SetContentFile
    self.content = open(filename, 'rb')
PermissionError: [Errno 13] Permission denied: 'c:/users/x/desktop/backup_saves'

I've tried running cmd as admin but am still getting the same permissions error. Any ideas?

ajdbnabad13
  • 355
  • 3
  • 11
  • 1
    Is c:/users/x/desktop/backup_saves a file? Looks diretory-ish to me. – tdelaney Aug 17 '20 at 05:07
  • backup_saves is a folder with multiple files inside of it, not a single file – ajdbnabad13 Aug 17 '20 at 05:09
  • 1
    If I got the documentation line right, [SetContentFile](https://pythonhosted.org/PyDrive/pydrive.html#pydrive.files.GoogleDriveFile.SetContentFile) is for uploading a file, not a directory. – tdelaney Aug 17 '20 at 05:10
  • Damn, I missed that when perusing the doc for what to use. Any ideas? I guess I can add some code to zip the folder beforehand so it's technically a file? – ajdbnabad13 Aug 17 '20 at 05:12
  • 1
    Yes, zip is a good option. You could also use glob or listdir to enumerate the file and do the CreateFile/SetContentFile/Upload for each. – tdelaney Aug 17 '20 at 05:15

1 Answers1

-2
  1. U need to check ur backup file is opening or not. if opening, close it.
  2. u can try it to move to another disk (D: or E:) to test first.