title: How do I delete folders in bash after successful copy (Mac OSX)?
body: <p>I recently created my first bash script, and I am having problems perfecting it's operation. I am trying to copy certain folders from one local drive, to a network drive.</p>
  
  <p>I am having the problem of deleting folders once they are copied over, sometimes the folder would be empty of contents, but the folder itself would remain, other times nothing would happen at all. Is there a better way to try to delete folders after rsync is done copying? I was trying to exclude the live tv buffer folder, but really, I can blow it away without consequence if need be.</p>
  
  <pre><code>#!/bin/bash
  
  network="CBS"
  useracct="tvcapture"
  thedate=$(date "+%m%d%Y")
  folderToBeMoved="/users/$useracct/Documents"
  newfoldername="/Volumes/Media/TV/$network/$thedate"
  
  ECHO "Network is $network"
  ECHO "date is $thedate"
  ECHO "source is $folderToBeMoved"
  ECHO "dest is $newfoldername"
  
  mkdir $newfoldername
  rsync -av $folderToBeMoved/"EyeTV Archive"/*.eyetv $newfoldername --exclude="Live TV Buffer.eyetv"
  
  # this fails when there is more than one *.eyetv folder
  if [ -d $newfoldername/*.eyetv ]; 
  then 
  #this deletes the contents of the directories
  find $folderToBeMoved/"EyeTV Archive"/*.eyetv \( ! -path $folderToBeMoved/"EyeTV Archive"/"Live TV Buffer.eyetv" \) -delete
  #remove empty directory
  find $folderToBeMoved/"EyeTV Archive"/*.eyetv -type d -exec rmdir {} \;
  fi
  </code></pre>