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
| def convert(path='/', ext=''):
for parent, dirnames, filenames in os.walk(path): for filename in filenames: extension = os.path.splitext(filename)[1]
if extension == ext:
old_dir = os.path.join(parent, filename) new_dir = old_dir.replace('.flac', '.m4a') ffmpeg_command = f'ffmpeg -i "{old_dir}" "{new_dir}" -y' p = subprocess.Popen(ffmpeg_command, shell=True, stdout=subprocess.PIPE) for line in iter(p.stdout.readline, b''): msg = line.strip().decode('gbk') print(msg)
convert(os.getcwd(), ext='.flac')
import os import subprocess
def remove(path='/', ext=''):
for parent, dirnames, filenames in os.walk(path): for filename in filenames: extension = os.path.splitext(filename)[1]
if extension == ext: dir = os.path.join(parent, filename)
print(dir) os.remove(dir)
|