LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2009, 06:33 PM   #1
ohmygoth
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
Question 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!
 
Old 12-05-2009, 07:17 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
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.
 
1 members found this post helpful.
Old 12-05-2009, 09:31 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
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;
}
 
1 members found this post helpful.
Old 12-05-2009, 09:38 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
I think he/she didnt want to use any "system" calls.
 
Old 12-05-2009, 09:40 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by nadroj View Post
I think he didnt want to use any "system" calls.
oops, missed that.
 
  


Reply

Tags
delete, directory, empty, rmdir



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vi delete empty line? Junior_DBA Linux - Newbie 5 09-11-2008 03:21 PM
vim how to delete until the first empty line edenCC Linux - Software 2 05-03-2007 10:26 PM
how to search for and delete empty directories? BrianK Programming 4 06-03-2005 07:24 AM
Empty Folder ? wlaw Linux - Networking 1 09-07-2004 03:42 AM
Delete Empty files whospeaks2me Linux - Newbie 2 07-18-2003 10:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration