SHARE
TWEET

copy_folder_by_filename

baptx Jan 26th, 2014 (edited) 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IFS=$'\n'
  2. if [ $# == 2 ]; then
  3.     if [ ! -d $1 ]; then
  4.         echo "Error: directory $1 does not exist"
  5.     else
  6.         dir=$1
  7.         len=$((${#dir} + 1))
  8.         if [ ! -d $2 ]; then
  9.             mkdir $2
  10.         fi
  11.         for i in `ls -R $1`
  12.         do
  13.             src=`echo $i | cut -d : -f 1`
  14.             if [ -d $src ]; then
  15.                 dir=$src
  16.             fi
  17.             dest=$2/`echo $dir | cut -c $len-`
  18.             if [ ! -d $dest ]; then
  19.                 mkdir $dest
  20.             fi
  21.             if [ -f $dir/$i ]; then
  22.                 cp -v $dir/$i $dest
  23.             fi
  24.         done
  25.     fi
  26. else
  27.     echo "On some MP3 player, the play order depends on wich files are copied first.
  28. Folder files will be copied alphabetically by filename, subfolders included.
  29.  
  30. Usage: $0 source_directory destination_directory"
  31. 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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top