forked from viswanathanTJ/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolder_mover.py
106 lines (98 loc) · 3.33 KB
/
folder_mover.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import glob
import shutil
fdir = r'B:\Notepad\Notepad'
os.chdir(fdir)
files = glob.glob('*.txt')
varisai = ' வரிசை'
global success_count
success_count = 0
def move(fname):
global success_count
fsrc = fdir + '\\' + fname
print('fsrc', fsrc)
fdest = os.getcwd()
print('fdest', fdest)
try:
# shutil.move(fsrc,fdest) # Don't overwrite
shutil.move(fsrc, os.path.join(fdest, fname))
print('Completed:', fname)
success_count = success_count + 1
except:
print('Error on Moving:', fname)
def e(arg):
return os.path.exists(arg)
for file in files:
os.chdir(fdir)
print('Processing:', file)
try:
fc = file[0]
sc = file[1]
tc = file[2]
foc = file[3]
fic = file[4]
sic = file[5]
if e('ஸ்ரீ வரிசை'):
os.chdir('ஸ்ரீ வரிசை')
print('done')
if e('ஸ்ரீ'+fic):
os.chdir('ஸ்ரீ'+fic)
move(file)
else:
os.chdir(fdir)
if e(fc):
shutil.move(os.path.join(fdir, file), os.path.join(os.path.join(fdir, fc), file))
# shutil.move(file, fc) # dont overwrite
elif e(fc+varisai):
os.chdir(fc+varisai)
if e(fc+sc+varisai):
os.chdir(fc+sc+varisai)
if e(fc+sc+tc+varisai):
os.chdir(fc+sc+tc+varisai)
move(file)
elif e(fc+sc+tc):
os.chdir(fc+sc+tc)
move(file)
elif e(fc+sc+tc+foc+fic):
os.chdir(fc+sc+tc+foc+fic)
move(file)
elif e(fc+sc+tc+foc+fic+varisai):
os.chdir(fc+sc+tc+foc+fic+varisai)
if e(fc+sc+tc+foc+fic+sic):
os.chdir(fc+sc+tc+foc+fic+sic)
move(file)
elif e(fc+sc+tc):
os.chdir(fc+sc+tc)
move(file)
elif e(fc+sc):
os.chdir(fc+sc)
move(file)
elif e(fc):
os.chdir(fc)
move(file)
elif e(fc+varisai):
os.chdir(fc+varisai)
if e(fc+sc):
os.chdir(fc+sc)
move(file)
elif e(fc+sc+varisai):
os.chdir(fc+sc+varisai)
if e(fc+sc+tc):
os.chdir(fc+sc+tc)
move(file)
elif e(fc+sc+tc+varisai):
os.chdir(fc+sc+tc+varisai)
if e(fc+sc+tc+foc+fic+sic):
os.chdir(fc+sc+tc+foc+fic+sic)
move(file)
elif e(fc+sc+tc+foc):
os.chdir(fc+sc+tc+foc)
move(file)
elif e(fc+sc+tc+foc):
os.chdir(fc+sc+tc+foc)
move(file)
except Exception as er:
print('Some Error while Processing:', file)
print(er)
print('Total File:', len(files))
print('Success:', success_count)