# Script ArtistTitle.txt
# Input argument - directory where all .mp3 files are located.
var str dir
# The script will rename all files that are UNDER this directory, that
# means files that are in subfolders, sub-subfolders, sub-sub-subfolders, tc.
var str list, file, name, artist, title, newname
# Collect a list of all files matching the pattern "*-*.mp3".
lf -r -n "*-*.mp3" $dir > $list
# Go thru files one by one.
while ($list <> "")
do
# Get the next file.
lex "1" $list > $file
# Get just the file name. It is after the last /.
stex -p "^/^l[" $file > $name
# Remove the .mp3 part.
stex -c "[^.mp3^" $name > null
# Get the artist. It is before the dash.
stex -p "]^-^" $name > $artist
# Get the title. It is after the dash.
stex -p "^-^[" $name > $title
# The new name of the file is $title, then dash, then $artist, then .mp3.
set $newname = $title + "-" + $artist + ".mp3"
# Rename file from $file to $newname. We will wrap both names in
# double quotes in case either name has space, etc.
system rename ("\""+$file+"\"") ("\""+$newname+"\"")
# We are done with this file. Next time around the loop, we will
# automatically get the next file with the lex command, since
# the next file is now the first line of $list.
done