944,142 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4710
  • C++ RSS
Jul 2nd, 2006
0

c++ or shell script to delete some files

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uxohus2b is offline Offline
5 posts
since Jul 2006
Jul 2nd, 2006
0

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

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Jul 2nd, 2006
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uxohus2b is offline Offline
5 posts
since Jul 2006
Jul 2nd, 2006
0

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

Quote 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.

C++ Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 2nd, 2006
0

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

Quote 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.

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
uxohus2b is offline Offline
5 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Connecting to and affecting programs with other programs.
Next Thread in C++ Forum Timeline: Pointer to a data member





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC