-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_manipulator.py
78 lines (61 loc) · 1.77 KB
/
file_manipulator.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
"""
Created on Sun Jan 14 15:31:02 2018
@author: channelCS
"""
import glob
import config as cfg
import os
from string import digits
import sys
if sys.platform[:3]=='win':
splitr='\\'
else:
splitr='/'
def move_files():
x=os.listdir(path)
print 'The folder has {} subfolders'.format(len(x))
for folder in x:
new_path=path+'/'+folder
if os.path.isdir(new_path):
y=os.listdir(new_path)
if y == []:
print 'Empty subfolder:',folder
else:
for file_ in y:
os.rename(new_path+'/'+file_,path+'/'+folder+'_'+file_)
if not os.listdir(new_path):
os.rmdir(new_path)
path=cfg.audio_folder
cfg.CreateFolder(cfg.audio_folder)
cfg.CreateFolder(cfg.kitchen_folder)
cfg.CreateFolder(cfg.nonverbal_folder)
cfg.CreateFolder(cfg.office_folder)
cfg.CreateFolder(cfg.speech_folder)
for f in glob.glob(cfg.orig_dataset_path):
g=f.split(splitr)[-1]
if g in cfg.kitchen_array:
cfg.MoveFolder(f, cfg.kitchen_folder+'/'+g)
elif g in cfg.nonverbal_array:
cfg.MoveFolder(f, cfg.nonverbal_folder+'/'+g)
elif g in cfg.office_array:
cfg.MoveFolder(f, cfg.office_folder+'/'+g)
elif g in cfg.speech_array:
cfg.MoveFolder(f, cfg.speech_folder+'/'+g)
move_files()
move_files()
#Delete DS_Store files
for f in glob.glob(path+'/*'):
x=f.split(splitr)[-1]
if x[-4:]!='.wav':
os.remove(path+'/'+x)
#Generating the meta file
str1=''
arr1=[]
for f in glob.glob(path+'/*'):
x=f.split(splitr)[1]
res = x.translate(None, digits).split('.')[0].split('_')[0]
arr1.append(res)
str1+='audio/'+x+'\t'+res+'\n'
file1 = open("meta.txt","w")
file1.write(str1)
file1.close()