deleting folder and entire contents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #1

    deleting folder and entire contents

    Hi,

    I've tried so many codes to delete folders that has other folders and files within them but no joy as to finding one that works. I get alot of permission denied....don't know how to get around this

    Any suggestions on one that does work?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    If you want to completely remove a non-empty directory, you must first remove all files and sub-directories from within it.

    Best way to deal with tasks like that is probably a recursive function:
    (in pseudocode)
    Code:
    function deleteDirectory(pathToDirector)
        foreach fileInDirectory
            unlink(fileInDirectory)
            
        foreach dirInDirectory
            deleteDirectory(dirInDirectory)
            
        rmdir(pathToDirectory)
    I suggest reading up on the readdir, unlink and rmdir functions.

    And you will of course have to have full permission on the directory and all it's files and sub-directories.

    Comment

    Working...