Skip to content

Instantly share code, notes, and snippets.

@baptx
Created October 12, 2014 14:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Copy folder by filename
IFS=$'\n'
if [ $# == 2 ]; then
if [ ! -d $1 ]; then
echo "Error: directory $1 does not exist"
else
dir=$1
len=$((${#dir} + 1))
if [ ! -d $2 ]; then
mkdir $2
fi
for i in `ls -R $1`
do
src=`echo $i | cut -d : -f 1`
if [ -d $src ]; then
dir=$src
fi
dest=$2/`echo $dir | cut -c $len-`
if [ ! -d $dest ]; then
mkdir $dest
fi
if [ -f $dir/$i ]; then
cp -v $dir/$i $dest
fi
done
fi
else
echo "On some MP3 player, the play order depends on wich files are copied first.
Folder files will be copied alphabetically by filename, subfolders included.
Usage: $0 source_directory destination_directory"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment