-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auto_Backup.py
55 lines (45 loc) · 1.25 KB
/
Auto_Backup.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import re
import psutil
import shutil
from time import sleep
def usb():
drps = psutil.disk_partitions()
drives = [dp.device for dp in drps if dp.fstype == 'FAT32']
d = str(drives)
res1 = "".join(re.split("[^a-zA-Z]*", d))
# os.chdir(res1+":/Backup")
finaldist = (res1+":/Backup")
# print(os.listdir())
return finaldist
def check():
drps = psutil.disk_partitions()
drives = [dp.device for dp in drps if dp.fstype == 'FAT32']
d = str(drives)
res1 = "".join(re.split("[^a-zA-Z]*", d))
# os.chdir(res1+":/Backup")
# print(os.listdir())
if res1.isalpha():
print("USB Connect")
return 1
else:
print("No USB")
return 0
if check() == 1:
source = ("C:\\Users\\arbaz\\Desktop\\Open-cv\\test")
os.chdir(source)
files = os.listdir()
print(files)
path = usb()
print(path)
for file in files:
try:
if os.listdir() != os.listdir(path):
shutil.copy(file,path)
print(file+ " Creating Backup")
else:
print(file +" present")
except:
print("Error")
else:
print("No USB Connected!")