c++ or shell script to delete some files

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 5
Reputation: uxohus2b is an unknown quantity at this point 
Solved Threads: 0
uxohus2b uxohus2b is offline Offline
Newbie Poster

c++ or shell script to delete some files

 
0
  #1
Jul 2nd, 2006
Hi,

Could someone tell me how I can delete files using a shell script or c++? The condition for deleting files: compare all files (say *.deb files) in folder A to those in folder B. If any file in B is also contained A, then delete the one in B.
This could probably done in two lines of shell scripting but I'm very new to programming.

Thanks in advance for your help. Regards, h.y.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: c++ or shell script to delete some files

 
0
  #2
Jul 2nd, 2006
what operating system? MS-Windows? use FindFirstFile() and FindNextFile() to get a list of all the files in dir A, store the filenames in a string array. Then use the same functions to get the files in directory B. For each file in B search the array of filenames you created from directory A, if found the delete the file.
Last edited by Ancient Dragon; Jul 2nd, 2006 at 9:06 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 5
Reputation: uxohus2b is an unknown quantity at this point 
Solved Threads: 0
uxohus2b uxohus2b is offline Offline
Newbie Poster

Re: c++ or shell script to delete some files

 
0
  #3
Jul 2nd, 2006
Thanks. I use Ubuntu and Windows. I'm looking for a shell script that does this. But I'll try what you're saying as well. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: c++ or shell script to delete some files

 
0
  #4
Jul 2nd, 2006
Originally Posted by uxohus2b
Thanks. I use Ubuntu and Windows. I'm looking for a shell script that does this. But I'll try what you're saying as well. Thanks.
Shell scripting is much easier. But this is not the forum for that. There is a UNIX support forum for scripting in daniweb. But you could try this.

  1. #!/bin/bash
  2. pathA='/blah/blah/blah/'
  3. pathB='/blah/blah/blah/blah/'
  4. ext="deb"
  5. for file in $(ls "$pathA"); do
  6. #
  7. # Only process DEB files.
  8. #
  9. file_ext=${file##*.}
  10. case $file_ext in
  11. deb | DEB )
  12. if [ -e "$pathB$file" ]; then
  13. echo deleting "$pathB$file"
  14. rm -f "$pathB$file"
  15. fi
  16. esac
  17. done
Last edited by WolfPack; Jul 2nd, 2006 at 11:37 pm.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 5
Reputation: uxohus2b is an unknown quantity at this point 
Solved Threads: 0
uxohus2b uxohus2b is offline Offline
Newbie Poster

Re: c++ or shell script to delete some files

 
0
  #5
Jul 2nd, 2006
Originally Posted by WolfPack
Shell scripting is much easier. But this is not the forum for that. There is a UNIX support forum for scripting in daniweb. But you could try this.

  1. #!/bin/bash
  2. pathA='/blah/blah/blah/'
  3. pathB='/blah/blah/blah/blah/'
  4. ext="deb"
  5. for file in $(ls "$pathA"); do
  6. #
  7. # Only process DEB files.
  8. #
  9. file_ext=${file##*.}
  10. case $file_ext in
  11. deb | DEB )
  12. if [ -e "$pathB$file" ]; then
  13. echo deleting "$pathB$file"
  14. rm -f "$pathB$file"
  15. fi
  16. esac
  17. done
Thanks very much for the code, and for directing me to the right forum. I really appreciate it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC