Register
It is currently Fri Oct 31, 2014 4:47 pm

Recycle bin in bash problem


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Jun 15, 2011 5:15 am   

Joined: Wed Jun 15, 2011 5:09 am
Posts: 1
I need to make a recycle bin code using bash my problem is that when i move a file with the same name in the trash folder i just overwrites the previous file can you give me any suggestions on how to approch this problem
Code:
#!/bin/bash

mkdir -p "$HOME/Trash"
touch "$HOME/.info"
if [ $1 = -restore ]; then
   argv=($*)
   for (( x = 1 ; x < ${#argv[*]} ; x++ ))
   do
      while read file; do
         path=$(basename $file)
         if [ "$path" = "${argv[x]}" ]; then
            mv $HOME/Trash/${argv[x]} /$file
            sed "/$path/d" /$HOME/.info >tmp
            mv tmp /$HOME/.info
         fi
      done < /$HOME/.info
   done
else
   if [ $1 = -restoreall ]; then
      while read file; do
         path=$(basename $file)
         mv $HOME/Trash/$path /$file
         sed "/$path/d" /$HOME/.info >tmp
         mv tmp /$HOME/.info
      done < /$HOME/.info
      mv $HOME/Trash/* /$PWD
   else
      if [ $1 = -empty ]; then
         rm -rfv /$HOME/Trash/*
         sed "/$HOME/d" /$HOME/.info >tmp
         mv tmp /$HOME/.info
      else
         args=($*)
         for (( i=0 ; i<${#args[*]} ; i++ ))
         do
            ABSOLUTE=$(readlink -f ${args[i]})
            mv $ABSOLUTE $HOME/Trash
            echo -e $ABSOLUTE>> /$HOME/.info
         done
      fi
   fi
fi


Top
 Profile  
 PostPosted: Wed Jun 15, 2011 2:57 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hello anjoz!

Was my post on the daniweb forums helpful? I saw that you'd incorporated 'readlink -f', but my post also covered ways to work around the problem of files with the same name :)

Thanks!
-Jeo (a.k.a. Gromit)

(including daniweb link for reference: http://www.daniweb.com/software-develop ... 63/1583061 )


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP