LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Delete folder not empty C++ (https://www.linuxquestions.org/questions/programming-9/delete-folder-not-empty-c-773721/)

ohmygoth 12-05-2009 06:33 PM

Delete folder not empty C++
 
Hi, I'm using rmdir(), and everything goes ok if the directory is empty, ¿how can I remove the entire tree when i have other files or directories in the folder that I want to delete?
I've read about using "system(rm....)" but i REALLY want to do this without it, is it possible?

Any help is very appreciated!

Thanx a lot!

nadroj 12-05-2009 07:17 PM

I dont think there is a standard C++ or UNIX call to do this. Simply iterate over all files and delete them; recursively deleting the files within subdirectories. I believe its easier than you may be thinking it is.

smeezekitty 12-05-2009 09:31 PM

how bout
Code:

#define DELETE_DIR(x) do {char b[255]; sprintf(b, "rm -r %s", (x)); system(b);} while(!1)
int  main(){
DELETE_DIR("/home/nick");
return 0;
}


nadroj 12-05-2009 09:38 PM

I think he/she didnt want to use any "system" calls.

smeezekitty 12-05-2009 09:40 PM

Quote:

Originally Posted by nadroj (Post 3781371)
I think he didnt want to use any "system" calls.

oops, missed that.


All times are GMT -5. The time now is 11:54 PM.