Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

FileOps.class.php

Go to the documentation of this file.
00001 <?php
00002 /* FileOps.class.php
00003 
00004     Class that provides a few functions to manage more easily the file
00005     operations, i.e. it allows to copy, delete and move directories
00006     recursively.
00007 */
00008 
00013 class FileOps
00014 {
00021         function ls_a($wh){
00022                 if ($handle = opendir($wh)) {
00023                         while (false !== ($file = readdir($handle))) {
00024                                 if ($file != "." && $file != ".." ) {
00025                                         if(!$files) $files="$file";
00026                                         else $files="$file\n$files";
00027                                 }
00028                         }
00029                         closedir($handle);
00030                 }
00031                 $arr=explode("\n",$files);
00032                 return $arr;
00033         }
00034 
00044         function cp($wf, $wto){
00045 
00046                 /* If the destination is a file, we abort */
00047                 if (file_exists($wto) && ! is_dir($wto))
00048                         return false;           
00049                 else if (file_exists($wto) && is_dir($wf))
00050                 {
00051                         $dest = basename($wf);
00052                         $wto = $wto . "/". $dest;
00053                         
00054                         mkdir($wto, 0777);
00055                 }       
00056                 else if (! file_exists($wto) && is_dir($wf))
00057                         mkdir($wto,0777);
00058                         
00059                 $arr=FileOps::ls_a($wf);
00060                 foreach ($arr as $fn){
00061                         if($fn){
00062                                 $fl="$wf/$fn";
00063                                 $flto="$wto/$fn";
00064 
00065                                 if(is_dir($fl)) 
00066                                 {
00067                                         FileOps::cp($fl,$flto);
00068                                 }
00069                                 else 
00070                                 {
00071                                         copy($fl,$flto);
00072                                 }
00073                         }
00074                 }
00075                 return true;
00076         }
00077         
00086         function rm($dir){
00087                 if (is_file($dir))
00088                 {
00089                         unlink($dir);
00090                 }
00091                 else
00092                 {
00093                         $current_dir = opendir($dir);
00094                         while($entryname = readdir($current_dir))
00095                         {
00096                                 if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!=".."))
00097                                 {
00098                                         FileOps::rm("${dir}/${entryname}");
00099                                 }
00100                                 elseif($entryname != "." and $entryname!="..")
00101                                 {
00102                                         FileOps::rm("${dir}/${entryname}");
00103                                 }
00104                         }
00105                         closedir($current_dir);
00106                         rmdir(${dir});
00107                 }               
00108         }
00109 }
00110 ?>

Generated on Wed Nov 19 20:29:34 2003 for James by doxygen 1.3.4