Created
March 8, 2016 17:58
-
-
Save jmcmellen/953629e01a6cd385d614 to your computer and use it in GitHub Desktop.
Go through files and do something to them. Uses multiprocessing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
from multiprocessing import Pool | |
def main(): | |
fileList = [] | |
for root, dirs, files in os.walk("."): | |
for file in files: | |
full_file = os.path.abspath("{0}\\{1}".format(root, file)) | |
if filter_it(filename=full_file): | |
fileList.append({'filename':full_file}) | |
p = Pool(processes=4) | |
result = p.map_async(process_it, fileList) | |
result.get() | |
print "Done" | |
def filter_it( *args, **kwargs): | |
#print kwargs['filename'][-3:] | |
if kwargs['filename'][-3:] == "wav": | |
return True | |
else: | |
return False | |
def process_it( *args, **kwargs): | |
print args[0] | |
filename = args[0]['filename'] | |
subprocess.call(["lame", "-h", "-S", filename, filename[:-3] + "mp3"]) | |
print "Finished with", filename | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment