Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Delete all files in directory Jump to:  
Category: >> PHP Code >> Delete all files in directory Bookmark and Share

<< lastnext >>

Snippet Name: Delete all files in directory

Description: This is a simple function that will take a folder path and remove all of its contents including files and directories.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009

 
<?PHP
 
FUNCTION emptyDir($path) { 
 
     // init the debug string
     $debugStr = '';
     $debugStr .= "Deleting Contents Of: $path<br /><br />";
 
     // parse the folder
     IF ($handle = OPENDIR($path)) {
 
          WHILE (FALSE !== ($file = READDIR($handle))) {
 
               IF ($file != "." && $file != "..") {
 
               // If it's a file, delete it
               IF(IS_FILE($path."/".$file)) {
 
                    IF(UNLINK($path."/".$file)) {
                    $debugStr .= "Deleted File: ".$file."<br />";     
                    }
 
               } ELSE {
 
                    // It's a directory...
                    // crawl through the directory and delete the contents               
                    IF($handle2 = OPENDIR($path."/".$file)) {
 
                         WHILE (FALSE !== ($file2 = READDIR($handle2))) {
 
                              IF ($file2 != "." && $file2 != "..") {
                                   IF(UNLINK($path."/".$file."/".$file2)) {
                                   $debugStr .= "Deleted File: $file/$file2<br />";     
                                   }
                              }
 
                         }
 
                    }
 
                    IF(RMDIR($path."/".$file)) {
                    $debugStr .= "Directory: ".$file."<br />";     
                    }
 
               }
 
               }
 
          }
 
     }
     RETURN $debugStr;
}
 
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 311 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?