Skip to content

Instantly share code, notes, and snippets.

@jmcmellen
Created March 8, 2016 17:58
Show Gist options
  • Save jmcmellen/953629e01a6cd385d614 to your computer and use it in GitHub Desktop.
Save jmcmellen/953629e01a6cd385d614 to your computer and use it in GitHub Desktop.
Go through files and do something to them. Uses multiprocessing.
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