-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsync.py
54 lines (46 loc) · 1.78 KB
/
sync.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
import sys
import os
import shutil
# if true will log the script
logging = 'false'
def log(string):
if logging == 'true':
print(string)
def copy(path_src,path_des):
# Copy the file
try:
log("FROM: " + path_src + " TO: " + path_des)
shutil.copy(path_src, path_des)
except:
log("File Exists")
def each_file(path_src, path_des):
# This loop will go through every folder and file
for folderName, subfolders, filenames in os.walk(path_src):
log('The current folder is ' + folderName)
# this will create the sub folders in the current folder
for subfolder in subfolders:
log('SUBFOLDER OF ' + folderName + ': ' + subfolder)
try:
# The current path of the src folder
# is replace with the path to new destination
# before replace: C\\src\\EXAMPLE_FOLDER
# after replace: C\\des\\EXAMPLE_FOLDER
new_path = folderName.replace(path_src,path_des)
os.mkdir(new_path+"\\"+subfolder)
except:
log("Folder Exists:" + subfolder)
for filename in filenames:
# Every file is copied base on where the
# os.walk(path) function is
# new_path is obtained by using same method of subfolders
new_path = folderName.replace(path_src,path_des)
file = folderName + '\\'+ filename
copy(file, new_path)
'''
"-d" use current dir as src and destination will be provided
"-s" use current dir as des and the source will be provided
'''
if sys.argv[1] == "-d":
each_file(os.getcwd(), sys.argv[2])
if sys.argv[1] =="-s":
each_file(sys.argv[2], os.getcwd())