Delete a non-empty directory programmatically - Unix

This is a discussion on Delete a non-empty directory programmatically - Unix ; 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...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Delete a non-empty directory programmatically

  1. Delete a non-empty directory programmatically

    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


  2. Re: Delete a non-empty directory programmatically

    On Oct 29, 1:45 pm, J de Boyne Pollard
    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


  3. Re: Delete a non-empty directory programmatically

    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

  4. Re: Delete a non-empty directory programmatically

    Chris Friesen 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.

  5. Re: Delete a non-empty directory programmatically

    On Oct 29, 11:42 pm, Chris Friesen 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?
    >
    > 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


+ Reply to Thread