IFS=$'\n' if [ $# -gt 0 ]; then if [ ! -f $1 ]; then echo "Error: file $1 does not exist" exit fi path=`echo $1 | rev | cut -d / -f 2- | rev` if [ $path == $1 ]; then path=$PWD fi fi if [ $# == 1 ]; then nb=0 for i in `cat $1` do if [ -f $path/$i ]; then let ++nb if [ $nb -lt 10 ]; then digit="00" elif [ $nb -lt 100 ]; then digit="0" else digit="" fi mv -v $path/$i $path/$digit$nb" - "$i fi done elif [ $# == 2 ] && [ $2 == "-r" ]; then for i in `ls $path` do name=`echo $i | cut -d - -f 2- | cut -c 2-` for j in `cat $1` do if [ $path/$name == $path/$j ]; then mv -v $path/$i $path/$name fi done done else echo "Playlist files will be renamed by playlist index. This script is designed for M3U playlists using relative paths. Playlist file needs to be in playlist files folder, subfolders not supported. You can use this script with other playlists if you convert them. Index uses 3 digits: playlist files are renamed alphabetically up to 999 files. Usage: $0 playlist [OPTION] OPTION: -r: remove index from filename (add by default)" fi