SHARE
TWEET

remame_by_playlist_index

baptx Jan 26th, 2014 (edited) 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IFS=$'\n'
  2. if [ $# -gt 0 ]; then
  3.     if [ ! -f $1 ]; then
  4.         echo "Error: file $1 does not exist"
  5.         exit
  6.     fi
  7.     path=`echo $1 | rev | cut -d / -f 2- | rev`
  8.     if [ $path == $1 ]; then
  9.         path=$PWD
  10.     fi
  11. fi
  12. if [ $# == 1 ]; then
  13.     nb=0
  14.     for i in `cat $1`
  15.     do
  16.         if [ -f $path/$i ]; then
  17.             let ++nb
  18.             if [ $nb -lt 10 ]; then
  19.                 digit="00"
  20.             elif [ $nb -lt 100 ]; then
  21.                 digit="0"
  22.             else
  23.                 digit=""
  24.             fi
  25.             mv -v $path/$i $path/$digit$nb" - "$i
  26.         fi
  27.     done
  28. elif [ $# == 2 ] && [ $2 == "-r" ]; then
  29.     for i in `ls $path`
  30.     do
  31.         name=`echo $i | cut -d - -f 2- | cut -c 2-`
  32.         for j in `cat $1`
  33.         do
  34.             if [ $path/$name == $path/$j ]; then
  35.                 mv -v $path/$i $path/$name
  36.             fi
  37.         done
  38.     done
  39. else
  40.     echo "Playlist files will be renamed by playlist index.
  41. This script is designed for M3U playlists using relative paths.
  42. Playlist file needs to be in playlist files folder, subfolders not supported.
  43. You can use this script with other playlists if you convert them.
  44. Index uses 3 digits: playlist files are renamed alphabetically up to 999 files.
  45.  
  46. Usage: $0 playlist [OPTION]
  47. OPTION: -r: remove index from filename (add by default)"
  48. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top