import os, subprocess from os.path import join, getsize import multiprocessing from multiprocessing.pool import ThreadPool target = 'D:/BMS/bmsbox/フォルダ分け済/copybms/' cmd = 'D:/BMS/bmstool/ffmpeg.exe -y -i ' success = 0 failure = 0 def call_oggenc(f): proc = subprocess.Popen(cmd + '\"' + f + '\" ' + '\"' + f.replace('.wav', '.ogg') + '\"') proc.wait() outs = proc.returncode if outs == 0: try: os.remove(f) except PermissionError: print('{}の削除に失敗'.format(f)) return outs with ThreadPool(4) as pool: for root, dirs, files in os.walk(target): print(root) files = [f for f in files if f.endswith('.wav')] results = [] for i in files: results.append(pool.apply_async(call_oggenc, (join(root, i),))) for result in results: result.wait() if result.get() == 0: success += 1 else: failure += 1 print('success:{}, failure:{}'.format(success, failure))