0

I'm trying to make a file that will back up my files to a directory when I wish for it to (I'm experimenting).

from infi.systray import SysTrayIcon
import time
import shutil

def backup(systray):
    newPath = shutil.copy(r"D:\Desktop\Random Ass Videos", 'D:\Desktop\Backup File')


menu_options = (("Backup", None, backup),)
systray = SysTrayIcon("RoseBackups.ico", "Rose Backup Tool", menu_options)
systray.start()

here is the code above ^^^

but when I run it I get the error:

PermissionError: [Errno 13] Permission denied: 'D:\\Desktop\\Random Ass Videos'

I thought it was because the file wasn't run as admin so I tried to add:

from infi.systray import SysTrayIcon
import time
import shutil

import admin
if not admin.isUserAdmin():
        admin.runAsAdmin()

but I got a problem as it couldn't find a module named 'admin' (I'm sure this is 100% my fault as I probably didn't install it correctly)

Any help counts, thanks all!

Alasdair
  • 3
  • 1

2 Answers2

0

Try running your script by right clicking it and pressing "Run as administrator"

gkpln3
  • 1,317
  • 10
  • 24
  • Can't run it directly as an admin as it doesn't have an option to. good idea though! – Alasdair Nov 27 '19 at 10:54
  • You can start a command prompt as admin: Press ctrl+shift+esc, then go to file->run, type cmd and select "Run as administrator". Now navigate to where your script is and try running it using "py -3 script_name.py") – gkpln3 Nov 27 '19 at 10:56
  • tried that, still get the error ```PermissionError: [Errno 13] Permission denied: 'D:\\Desktop\\Random Ass Videos''``` – Alasdair Nov 27 '19 at 11:02
0

You can not copy folder to folder with shutil.copy instead use,

import shutil
shutil.copytree("D:\\Desktop\\Random Ass Videos", 'D:\\Desktop\\Backup File')
Khakhar Shyam
  • 459
  • 2
  • 11
  • Thank you so much, the odd thing is I tried this and got the same "permission error" and I thought there was no hope, then when I copy yours it works first time. – Alasdair Nov 27 '19 at 11:12