Convert all .ape files to .flac in different subfolders
The command that you need is:
find /path/to/MainDir/ -type f -name "*.ape" -execdir sh -c ' avconv -i "$1" "${1%.ape}.flac" ' _ {} \;
This will find each file that has .ape
suffix and then convert it with the same filename with .flac
suffix to the same location as original file is located.
{}
is the path of current found file.
See the test from here
The (python) script below should do the job. Copy it into an empty file, save it as convert.py
, set the directory to the files in the head section of the script (convert_dir =
) and run it by the command:
python3 /path/to/convert.py
The script
#!/usr/bin/env python3
convert_dir = "/path/to/folder/tobeconverted"
import os
import subprocess
for root, dirs, files in os.walk(convert_dir):
for name in files:
if name.endswith(".ape"):
# filepath+name
file = root+"/"+name
# to use in other (convert) commands: replace the "avconv -i" by your command, and;
# replace (".ape", ".flac") by the input / output extensions of your conversion
command = "avconv -i"+" "+file+" "+file.replace(".ape", ".flac")
subprocess.Popen(["/bin/bash", "-c", command])
else:
pass
Now that ffmpeg is preferred over avconv again, and there are cheap many core computers ($60 for an 8 core XU4) I fount the following to be most effective;
#!/bin/bash
#
# ape2flac.sh
#
function f2m(){
FILE=$(echo "$1" | perl -p -e 's/.ape$//g');
if [ ! -f "$FILE".flac ] ; then
ffmpeg -v quiet -i "$FILE.ape" "$FILE.flac"
fi
}
export -f f2m
find "$FOLDER" -name '*.ape' | xargs -I {} -P $(nproc) bash -c 'f2m "$@"' _ "{}"