| | |
c++ or shell script to delete some files
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
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.
•
•
•
•
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.
C++ Syntax (Toggle Plain Text)
#!/bin/bash pathA='/blah/blah/blah/' pathB='/blah/blah/blah/blah/' ext="deb" for file in $(ls "$pathA"); do # # Only process DEB files. # file_ext=${file##*.} case $file_ext in deb | DEB ) if [ -e "$pathB$file" ]; then echo deleting "$pathB$file" rm -f "$pathB$file" fi esac done
Last edited by WolfPack; Jul 2nd, 2006 at 11:37 pm.
バルサミコ酢やっぱいらへんで
•
•
Join Date: Jul 2006
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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)
#!/bin/bash pathA='/blah/blah/blah/' pathB='/blah/blah/blah/blah/' ext="deb" for file in $(ls "$pathA"); do # # Only process DEB files. # file_ext=${file##*.} case $file_ext in deb | DEB ) if [ -e "$pathB$file" ]; then echo deleting "$pathB$file" rm -f "$pathB$file" fi esac done
![]() |
Similar Threads
- Shell Script to Zip / FTP / Delete transactional files. (Shell Scripting)
- For Pay Shell Script - Zip / FTP / Delete transactional files (Shell Scripting)
- How to delete files in UNIX using shell script (Shell Scripting)
- Why my shell script doesn't delete a file ?? (Shell Scripting)
Other Threads in the C++ Forum
- Previous Thread: Connecting to and affecting programs with other programs.
- Next Thread: Pointer to a data member
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






