LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   910705 - rmdir() doesn't remove empty dirs. (https://www.linuxquestions.org/questions/linux-newbie-8/910705-rmdir-doesn%27t-remove-empty-dirs-4175429058/)

hamidi2 09-26-2012 01:45 AM

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

evo2 09-26-2012 01:50 AM

Hi,

would help if you said what language you are using.

Evo2.

hamidi2 09-26-2012 05:03 AM

C/C++

evo2 09-26-2012 06:44 PM

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.

hamidi2 09-26-2012 11:10 PM

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?

evo2 09-26-2012 11:29 PM

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.

chrism01 09-27-2012 12:07 AM

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


All times are GMT -5. The time now is 03:11 AM.