-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.py
34 lines (29 loc) · 1014 Bytes
/
funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os, pathlib, shutil
from datetime import datetime
def getTime():
return "[" + datetime.now().strftime("%d/%m/%y %H:%M") + "] "
def IsFROMValid(path):
#Check if the path to backup exists
if(pathlib.Path(path).is_dir() or pathlib.Path(path).is_file()):
return True
else:
return False
def IsTOValid(path):
#Check if the path to save the backups in exists and is not a file
if(pathlib.Path(path).is_dir() and not pathlib.Path(path).is_file()):
return True
else:
return False
def MakeBackup(FROM, TO):
try:
if(pathlib.Path(FROM).is_dir()):
if pathlib.Path(TO).exists():
shutil.rmtree(TO)
shutil.copytree(FROM, TO)
else:
filename = os.path.basename(FROM)
shutil.copyfile(FROM, F"{TO}/{filename}")
return
except PermissionError:
print("The permission to access a directory has been denied. Try running SSBT as an administrator.")
exit()