emulating windows like delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting emulating windows like delete
# 1  
Old 07-13-2012
emulating windows like delete

Hi,

Trying to create a way of emulating the windows like delete environment. I have everything working apart from deleting a single folder. Such as if I have a folder with a folder it will delete the folder inside the folder but not the pervious folder and it will delete a file win that folder just not the first folder.



Code:
  moveFile(){
                  #check if file/directory exists
                  if [ $(doesFileOrDirectoryExist $1) == "true" ]
                  then
                                  filesToRemove=$(ls $1)
                                  #if there's too many files/directories then send them to the moveFiles functions
                                  if [ ${#filesToRemove[*]} -gt 1 ]
                                  then
                                                  moveFiles $filesToRemove                          
                                  else
   
                                                  #Directory handling
                                                  if [ $(isDirectory $1) == "true" ]
                                                  then
                                                                  #R Flag - check if for the selected directory, the rR flag is in place
                                                                  if [ $optionRFlag == "false" ]
                                                                  then
                                                                                  echo "rm: cannot remove \`$1': Is a directory"    
                                                                  else
                                                                                  descend=true
                                                                                  #I Flag - check if for the selected directory, the I flag is in place and prompt the user
                                                                                  if [ $optionIFlag == "true" ] && [ $(isDirectoryEmpty $1) == "false" ]
                                                                                  then
                                                                                                  read -p "rm: descend into directory \`$1'?" descendDir
                                                                                                  case $descendDir in
                                                                                                  y* | Y*)
                                                                                                                  descend="true" ;;
                                                                                                  *)
                                                                                                                  descend="false" ;;
                                                                                                  esac
                                                                                  
                                                                                  fi             
                                                                                  if [ $descend == "true" ]
                                                                                  then
                                                                                                  #list everything in your descend directory but give the whole path.  
                                                                                                  #sed - preceed each item with the present working directory
                                                                                                  subfiles=$(ls $1 | sed "s;^;`pwd`/$1/;")
                                                                                                  
                                                                                                  moveFiles $subfiles
                                                                                                  #Move the empty directory
                                                                                                  if [ $(isDirectoryEmpty $1) == "true" ]
                                                                                                  then      
                                                                                                                  delete=true
                                                                                                                  if [ $optionIFlag == "true" ] 
                                                                                                                  then
                                                                                                                                  read -p "rm: remove directory \`$1'?" deleteDir
                                                                                                                                  case $deleteDir in                            
                                                                                                                                  y* | Y*) 
                                                                                                                                                   delete="true" ;;
                                                                                                                                  *)
                                                                                                                                                  delete="false" ;;
                                                                                                                                  esac
                                                                                                                  fi
                                                                                                  
                                                                                                                  if [ $delete == "true" ]
                                                                                                                  then      
                                                                                                                                  mv $1 $recycleDirectory
                                                                                                                                  #V Flag - for the current directory/item, check if the v flag is active if so add informative text
                                                                                                                                  if [ $optionVFlag == "true" ]
                                                                                                                                  then
                                                                                                                                                  echo "removed directory: \`$1'"
                                                                                                                                  fi
                                                                                                                  fi
                                                                                                  fi
                                                                                  fi
                                                                  fi
                                                  else
                                                                  #File handling
                                                                  agreed=true
                                                                  if [ $optionIFlag == "true" ]
                                                                  then
                                                                                  read -p "$(getInteractiveMessage $1)" userAccepts
                                                                                  case $userAccepts in
                                                                                  y* | Y*)
                                                                                                  agreed="true" ;;
                                                                                  *)
                                                                                                  agreed="false" ;;
                                                                                  esac
                                                                  fi
                                                                  #refer to above i flag
                                                                  if [ $agreed == "true" ]
                                                                  then      
                                                                  
                                                                                  mv $1 $recycleDirectory
                                                                                  if [ $optionVFlag == "true" ]
                                                                                  then
                                                                                                  echo "removed \`$1'"
                                                                                  fi
                                                                  fi
                                                  fi
                                  fi
                  else
                                  
                                  echo "rm: cannot remove \`$1': No such file or directory"
                  fi
  }

# 2  
Old 07-13-2012
I am not sure what you mean. Do you want to empty a directory? Like for example:

Code:
$ ls -R testfolder
fileb	test1

testfolder/test1:
filea
$ rm -r testfolder/*
$ ls -R testfolder
$

# 3  
Old 07-13-2012
just rm -r test/

because if i have test/test1/
rm -r test/ <--- works

just doesnt work if i have an empty folder so
rm -r test/ <--- doesnt work

so basically the parent folder isnt being deleted

---------- Post updated at 08:22 PM ---------- Previous update was at 12:47 PM ----------

i think the issue is this part

Code:
subfiles=$(ls $1 | sed "s;^;`pwd`/$1/;")


Last edited by limpep; 07-13-2012 at 10:25 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

scp to windows and delete files from windows

Hi Team, I Have list file in Unix server, I need to copy files from Windows to Unix for the list of files given in Unix list file. after coping files to unix, I need to delete the files from Windows. i used SCP and moved files from windows to unix based on list file is done and working.... (1 Reply)
Discussion started by: spradeep86
1 Replies

2. Shell Programming and Scripting

Unix shell script to delete files on windows server

Hi experts, can anyone suggest me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (2 Replies)
Discussion started by: chpradeepch
2 Replies

3. UNIX for Dummies Questions & Answers

emulating cat in sed with q option

Hi, I am aware that the below are the equivalent in sed for cat command. sed ':' sed -n 'p' Is there any way to emulate the same using "q" option in sed? Thanks (8 Replies)
Discussion started by: pandeesh
8 Replies

4. Shell Programming and Scripting

Using RCP to copy and delete the files from Windows Drive

Hi, I have a requirement to copy the files from C drive on Windows to UNIX, once the files are copied I need to delete them from that drive (C:). A drive is also on same network as my unix, so I was asked to use RCP for copying the files. Can any one have the syntax to copy the files from... (0 Replies)
Discussion started by: Raamc
0 Replies

5. Red Hat

Emulating rm command

I just need to edit the "rm" command such that it should move all the files / directories to particular folder instead of deleting. Its regarding my dessertation work , started working on the source code coreutils/src/rm , can any one guide mw to create a new source code for "rm " such that it... (0 Replies)
Discussion started by: jakris
0 Replies

6. Shell Programming and Scripting

How do I Get the Title of My Putty Window (Emulating an XTerm)

I have a Perl script that changes the terminal window title and I would like to reset it to the original value when I am done. We are using Putty which emulates xterm. We are not running X-Windows so I can't use something like xprop (can I?). I'm using XTerm control codes to change the title and I... (2 Replies)
Discussion started by: NateTut
2 Replies

7. Programming

Xlib programming - Emulating left click press/released

Hi, Lately my university asked me to develop an application to be installed on some computers for the disabled. I've developed a head tracking software (it moves the cursor on the screen following your head's movements using a webcam), and it works greatly so far except for a missing feature.... (2 Replies)
Discussion started by: BlackLight
2 Replies

8. Shell Programming and Scripting

Looking for a perl script (windows) to delete the contents of a file

Hi All, Im having a file named logserver.txt. I want a perl script to take a backup of that file, along with the datestamp; move the file to a different location or empty the contents of the file after backup. Remember, the file gets generated when the related service starts. My condition is... (14 Replies)
Discussion started by: ntgobinath
14 Replies

9. Shell Programming and Scripting

emulating rm command

Hi everyone! I am trying to write a bash script to emulate the rm command, I want to save all files I delete, a bit like the recycle bin in a windows OS. My script so far is below, I still need to amend a few things, once complete I plan to alias the script to rm and use it as a safe delete... (7 Replies)
Discussion started by: jack1981
7 Replies
Login or Register to Ask a Question