emulate windows like delete on unix
===

So basically I am trying to create a script in bash shell which will emulate the windows delete features. 

So instead of deleting a file or a folder it will move it to the recycle bin. I've got everything working apart from an issue I am having with moving folders into the recycle bin.

For example if I have a empty folder and run my script safe_rm it will not move the folder to the bin. However if I have a child folder in that parent folder it will delete both parent and child, so 

safe_rm -r dir1/ <--wont delete 

but

safe_rm dir1/ with content of dir2 file1 (dir1/file1 dir1/dir2) will delete.

Here is my code i am having an issue with


    moveFilesFolder(){
     #check if file/directory exists
        if [ $(checkFileFolder $1) == "true" ]
        then
          movingFilesToRemove=$(ls $1)
          #if there's too many files/directories then send them to the moveFiles functions
          if [ ${#movingFilesToRemove[*]} -gt 1 ]
          then
            movingFiles $movingFilesToRemove
          else
          #folder handling  
            if [ $(isFolder $1) == "true" ]
            then
              #we check the rR flag for selected folder  
              if [ $optionRFlag == "false" ]
              then
                echo "rm: cannot remove \`$1': Is a directory"
             else
               lvlDown=true
               #we check if the I argument used on the folder,
                   #which prompts the user
               if [ $optionIFlag == "true" ] && [ $(isFolderEmpty $1) == "false" ]
                then
                  read -p "rm: descend into directory \`$1'?" downFolder
                  case $downFolder in
                  y* | Y*)
                    lvlDown="true" ;;
                  *)
                    lvlDown="false" ;;
                  esac
     
                fi
                if [ $lvlDown == "true" ]
                then
                  #now we display all the descending folders and gives full path
                  #i will be using the sed command to handle sub files 
                  #this will proceed every item with present working folde
              subfiles=$(ls $1 | sed "s;^;`pwd`/$1;")
               # subfiles=$(ls $1 | grep '^d' )
               # subfiles=$(ls -R | grep ":" | sed "s/://" )  
               
               movingFiles $subfiles
                #now we move the empty folder 
                  if [ $(isFolderEmpty $1) == "false" ]  
                  then
                    dlt=true
        if [ $optionIFlag == "true" ] 
        then
                     read -p "rm: remove directory \`$1'?" deleteFolder
                     case $deleteFolder in
                     y* | Y*)
                        dlt="true" ;;
                     *)
                        dlt="false" ;;
                     esac
                   fi
    
                   if [ $dlt == "true" ]
                   then
                     mv $1 $recycleFolder
                    echo `pwd` 
                     if [ $optionVFlag == "true" ]
                     then
                       echo "removed directory: \`$1'"
                     fi
                   fi
                 fi
               fi
             fi
           else
             #here we are dealing with file handling 
             agreed=true
             if [ $optionIFlag == "true" ]
             then
               read -p "$(interMessage $1)" userAccepts
               case $userAccepts in
               y* | Y*)
                 agreed="true" ;;
               *)
                 agreed="false" ;;
               esac
             fi
             #refer to above i flag
             if [ $agreed == "true" ]
             then
    
               mv $1 $recycleFolder
               echo `pwd`
               if [ $optionVFlag == "true" ]
               then
                 echo "removed \`$1'"
               fi
             fi
           fi
         fi
       else
    
         echo "rm: cannot remove \`$1': No such file or directory"
       fi
    
    }
     