LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-26-2012, 01:45 AM   #1
hamidi2
Member
 
Registered: Aug 2012
Posts: 61

Rep: Reputation: Disabled
910705 - rmdir() doesn't remove empty dirs.


i may use system("rm -r ...") instead of rmdir("..."), because rmdir() has no option to remove files inside the dir as well as the dir itself and it expects it to be empty.
but, is there any better way not to call a shell command?
thx

Last edited by hamidi2; 09-26-2012 at 01:57 AM.
 
Old 09-26-2012, 01:50 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

would help if you said what language you are using.

Evo2.
 
Old 09-26-2012, 05:03 AM   #3
hamidi2
Member
 
Registered: Aug 2012
Posts: 61

Original Poster
Rep: Reputation: Disabled
C/C++
 
Old 09-26-2012, 06:44 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

for c++ I'd use boost. For example
Code:
#include "boost/filesystem.hpp"
int main()
{
	boost::filesystem::remove_all("foo");
}
Then..
Code:
mkdir -p foo/bar foo/baz
g++ -lboost_filesystem -lboost_system ra.cc
./a.out
HTH,

Evo2.
 
1 members found this post helpful.
Old 09-26-2012, 11:10 PM   #5
hamidi2
Member
 
Registered: Aug 2012
Posts: 61

Original Poster
Rep: Reputation: Disabled
thx. it's indeed an additional library and this means that it's not possible to do it with a call to a standard library API, right?
 
Old 09-26-2012, 11:29 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

Correct. AFAIR not all OSs have the concept of directories, this is why there are no native c/c++ builtins for anything to do with directories. IMHO, using libraries like boost is preferable over shell commands.

Evo2.
 
1 members found this post helpful.
Old 09-27-2012, 12:07 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,329

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
See https://www.gnu.org/software/libc/ma...Deleting-Files for unlink, rmdir, remove
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
dirs in /proc/acpi empty anibis Linux - Laptop and Netbook 1 07-18-2006 01:37 AM
Perl does not want rmdir an empty directory keefaz Programming 6 05-05-2005 01:59 AM
how to delet non-empty dirs bernstein Linux - General 6 04-30-2005 01:07 AM
rmdir for non-empty folder Zaius Linux - General 2 01-09-2004 10:09 PM
RMDIR - how to remove a non-empty directory?? jacksmash Linux - Newbie 15 11-23-2003 12:51 PM


All times are GMT -5. The time now is 07:48 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration