Sunday, 15 April 2012

bash scrupt to copy all songs in an m3u list into a folder

This is not the first time I thought about it and it took a lot of digging and googling in order to get the right command line to do it. So, all credit goes to the thefekete.net who is the initial poster and my only contribution is turning the initial command line into a script.

#!/bin/bash

# ------------------------------------------------------------------------------------
# Copy all files from a playlist to a dest folder
# ------------------------------------------------------------------------------------
if [ "$#" != 2 ]; then
 echo usage $0 playlist.m3u dest-dir
 exit 1
fi

if [ ! -d "$2" ]; then
    mkdir $2
    echo Creating directory `pwd`"/"$2
fi

if [ -z "$1" ]; then
 echo  $1 is not a valid file
 exit 2
fi

cat "$1" | grep -v '#' | while read i; do cp "${i}" "$2" ; echo "${i}"; done

Thank you the thefekete

No comments:

Post a Comment

I have had so many good people trying to promote various community oriented sites through here. Therefore all comments will first have to come through me... so I get a chance to learn about the interesting sites before you do ...