I have found a useful shell script that shows all files in a directory recursively.
Where it prints the file name echo "$i"; #Display File name.
I would instead like to run an ffmpeg command on non MP3 files, how can I do this? I have very limited knowledge of shell scripts so I appreciate if I was spoon fed! 🙂
//if file is NOT MP3
ffmpeg -i [the_file] -sameq [same_file_name_with_mp3_extension]
//delete old file
Here is the shell script for reference.
DIR="."
function list_files()
{
if !(test -d "$1")
then echo $1; return;
fi
cd "$1"
echo; echo `pwd`:; #Display Directory name
for i in *
do
if test -d "$i" #if dictionary
then
list_files "$i" #recursively list files
cd ..
else
echo "$i"; #Display File name
fi
done
}
if [ $# -eq 0 ]
then list_files .
exit 0
fi
for i in $*
do
DIR="$1"
list_files "$DIR"
shift 1 #To read next directory/file name
done
You can do the same with a find one-liner. Assuming the files you want to process are all wav:
If you want to find “rm” files, and delete them after conversion:
That said, if you want to do it with the shell script you showed, take the line that says
replace it with this:
$i is a variable. A few lines up, you have:
this basically means “for every element in * (which in turn stands for all files in the current directory, it’s what’s called a “shell expansion”), put the name of the element/file in the variable i, and then execute all the code between “do” and “done” “. So for each iteration, i will contain the name of one of the files in this directory.
There’s also a section that tests whether i is a directory and if so, it recursively lists its contents.
A quick final note: the \; at the end of the find command IS significant and it NEEDS to have a space before the backslash, otherwise it won’t work.