-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroomsize.py
25 lines (21 loc) · 847 Bytes
/
roomsize.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
import os
import re
from shutil import copyfile
from functools import reduce
origPath = '/seagate2t/rec_jan12/exp1'
savePath = '/seagate2t/rec_jan12/room'
if not os.path.exists(savePath):
os.makedirs(savePath)
for root, rooms, files in os.walk(origPath):
print(rooms)
for room in rooms:
print(room)
size = [float(s) for s in re.findall('[^,,]+', room)]
volume = reduce(lambda x, y: x*y, size)
for subroot, subdirs, subfiles in os.walk(os.path.join(origPath,room)):
print(subfiles)
for f in subfiles:
fRe = re.sub('.*_',str(int(volume))+'_',f)
#print(f, 'will be replaced by', fRe)
os.rename(os.path.join(subroot, f), os.path.join(subroot, fRe))
copyfile(os.path.join(subroot, fRe), os.path.join(savePath, fRe))