Skip to content

Instantly share code, notes, and snippets.

@fredmajor
Created May 28, 2019 04:23
Show Gist options
  • Save fredmajor/ac01b9bf0d42639e5fafb2d4d7e1f438 to your computer and use it in GitHub Desktop.
Save fredmajor/ac01b9bf0d42639e5fafb2d4d7e1f438 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This program finds (recursively) all ".wav" files in the current
# directory, converts them to ".flac" and deletes original ".wav" files.
# Requires "sox" to be installed. (sudo apt install sox)
SOURCE_EXT="wav"
TARGET_EXT="flac"
# https://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names
find . -type f -name "*.$SOURCE_EXT" -print0 | while IFS= read -r -d '' file
do
f_basename=$(basename "$file")
# strips out extension from file name
f_basename_no_ext="${f_basename%.*}"
f_dir=$(dirname "$file")
target_file="$f_dir/$f_basename_no_ext.$TARGET_EXT"
echo "$file -> $target_file"
sox "$file" "$target_file"
rm "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment