-
Notifications
You must be signed in to change notification settings - Fork 0
/
plha2Win.py
57 lines (47 loc) · 1.62 KB
/
plha2Win.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
# -*-coding:utf-8 -*
# Here is the script for PLHA2 for Laurent
# Here are handled files PLHA#####.* which must be
# moved to their directory PLHA#####
# Files PLHA#####.* and directories PLHA##### take
# place at the same level (i.e. superdirectory)
# before being handled.
import os
import shutil
os.chdir("path\to\the\right\superdirectory")
# Path to the superdirectory where files and
# directories to handle take place.
# (1) Making the list of files in the superdirectory (1)
filelist = []
for (dirpath, dirnames, filenames) in os.walk(os.getcwd()):
filelist.append(filenames)
break
try:
test = filelist[1]
print('An error occured : Please verify the path')
except:
filelist = filelist[0]
# (1) End of (1)
# (2) Moving the files (2)
cwd_name = os.getcwd().split("\")[-1]
end_index = len(cwd_name) + 5
j, k = 0, len(filelist)
for element in filelist:
box = element[0:end_index] + '\' + element
try:
shutil.move(element, box)
except:
j += 1
continue
# (2) End of (2)
# Final report :
print('Final report (3 lines follow) :')
print(k, ' file(s) examined.')
print(k-j, ' file(s) relocated.')
print(j, ' file(s) remained in place.')
#input("Press 'Entry key' to close this program...")
# For linux use, cancel the eventual # at the beginning of the upper line (beginning with input)
# and put a # (if not yet) at the beginning of the following one.
os.system("pause")
# For Windows use, cancel the eventual # at the beginning of the just upper
# line (beginning with os.system) and put a # (if not yet) at the beginning of the upper line beginning
# with : input("Press 'Entry key' to ...")