|
Home > Archive > Unix Programming > October 2007 > Delete a non-empty directory programmatically
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Delete a non-empty directory programmatically
|
|
| J de Boyne Pollard 2007-10-29, 1:23 pm |
| RC> Please help me understand, how can I delete a non-emmpty
RC> directory in unix programmatically ( in C language).
man opendir ; man readdir ; man closedir ; man -S 2 unlink ; man -S 2
rmdir
| |
|
| On Oct 29, 1:45 pm, J de Boyne Pollard <j.deboynepoll...@tesco.net>
wrote:
> RC> Please help me understand, how can I delete a non-emmpty
> RC> directory in unix programmatically ( in C language).
>
> man opendir ; man readdir ; man closedir ; man -S 2 unlink ; man -S 2
> rmdir
You can not do that easily. What you should do is unlink all the files
in the directory, recursively call the same function for any
directories inside, and after that rmdir() the directory.
That's exactly what rm -r does, since -r stands for recursively. And
that's the easier solution - call system( "rm -r directory_name" ),
and the command will do it for you.
Cheers,
Darko
| |
| Chris Friesen 2007-10-29, 7:22 pm |
| Darko wrote:
> That's exactly what rm -r does, since -r stands for recursively. And
> that's the easier solution - call system( "rm -r directory_name" ),
> and the command will do it for you.
You are aware that using system() has various security implications, as
well as often blocking the original caller with signals disabled?
Chris
| |
| SM Ryan 2007-10-30, 1:36 am |
| Chris Friesen <cbf123@mail.usask.ca> wrote:
# Darko wrote:
#
# > That's exactly what rm -r does, since -r stands for recursively. And
# > that's the easier solution - call system( "rm -r directory_name" ),
# > and the command will do it for you.
#
# You are aware that using system() has various security implications, as
# well as often blocking the original caller with signals disabled?
Then do a fork/exec/wait. /bin/rm has been well exercised and
likely fulfills everyone's expectation of what to do. For example
do you just unlink a symbolic link, or recursively delete through
it? Did you remember to check for them?
--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
| |
|
| On Oct 29, 11:42 pm, Chris Friesen <cbf...@mail.usask.ca> wrote:
> Darko wrote:
>
> You are aware that using system() has various security implications, as
> well as often blocking the original caller with signals disabled?
>
> Chris
Yeah, right. The gentleman here has problems with removing a non-empty
directory, and you're coming forward with hi-tech security
implications, mentioning signals and blocking etc? Don't you think
there's time and place for everything?
Cheers,
Darko
|
|
|
|
|