p@24: """ p@24: Source code: p@24: https://github.com/sidsig/ICASSP-MLP-Code/blob/master/utils.py p@24: """ p@24: p@24: import os p@24: p@24: def getFiles(root_dir,ext='.mp3',verbose=True) : p@24: """ p@24: Returns a list of files p@24: """ p@24: fileList=[] p@24: if verbose: p@24: print "Populating %s files..."%ext p@24: for (root,dirs,files) in os.walk(root_dir): p@24: for f in files: p@24: if f.endswith(ext): p@24: filePath=os.path.join(root,f) p@24: fileList.append(filePath) p@24: if verbose: p@24: print "%i files found."%len(fileList) p@24: return fileList p@24: p@24: def parseFile(filePath): p@24: """ p@24: Parses the file path and returns (root,fileName,ext) p@24: """ p@24: root,file=os.path.split(filePath) p@24: fileName,fileExt=os.path.splitext(file) p@24: return (root,fileName,fileExt) p@24: p@24: def read_file(filename): p@24: """ p@24: Loads a file into a list p@24: """ p@24: file_list=[l.strip() for l in open(filename,'r').readlines()] p@24: return file_list p@24: p@24: def writeFile(dataList,filename): p@24: with open(filename,'w') as f: p@24: f.writelines(dataList)