Convert files on directories that are not always there

走远了吗. 提交于 2019-12-11 02:45:35

问题


I've got a script that runs when a torrent download is finished to see if there are FLAC audio files and if yes convert them to MP3. Until today I've used:

for file in "$torrentpath"/"$torrentname"/*.flac
do
    ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}"

done

But I realised that when a torrent comes containing sub-directories the script is useless. I've tried messing around for the past few days with "find" and "if" and other ways but I can't really see the answer. I know it's there.

The script should just test if there are sub-dirs and execute ffmpeg on those, otherwise directly go with the conversion.

Any little hint will be appreciated.


回答1:


to handle arbitrary subdirectories in bash:

shopt -s globstar nullglob
for file in "$torrentpath/$torrentname"/**/*.flac
do ...



回答2:


find "$torrentpath"/"$torrentname" -name '*.flac' -print | while read file; do
    ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}"
done


来源:https://stackoverflow.com/questions/19987160/convert-files-on-directories-that-are-not-always-there

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!