Location: PHPKode > projects > WebSecurityTester > php-gtk/security/lib/FileSystem.lib.php
<?
function DirectoryRead($dirPath){
	$Content = array();
	if(file_exists($dirPath)){
		$handle = opendir($dirPath);
		while(false !== ($file = readdir($handle))){
			if ($file != "." && $file != "..")
				$Content[]=$file;
		}
		closedir($handle);
	}
	return $Content;
}

function FileRead($FilePath,$mode='rb'){
	$Content='';
	if (file_exists($FilePath)){
		$fs = filesize($FilePath);
		if($fs>0){
			$fp = fopen($FilePath, $mode);
			$Content = fread($fp, $fs);
        	fclose($fp);
		}
	}else
		$Content='';
	return $Content;
}

function FileWrite($FilePath, $Content){
	$fp = fopen($FilePath, "wb+");
	$Content = fwrite($fp,$Content);
	fclose($fp);
	return $Content;
}

function cp($wf, $wto){
	if (!file_exists($wto)){
		mkdir($wto,0777);
	}
	$arr=DirectoryRead($wf);
	foreach ($arr as $fn){
		if($fn){
			$fl="$wf/$fn";
			$flto="$wto/$fn";
			if(is_dir($fl))
				cp($fl,$flto);
			else
				copy($fl,$flto);
		}
	}
}

function deldir($dir){
	$current_dir = opendir($dir);
	while($entryname = readdir($current_dir)){
		if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
			deldir("$dir/$entryname");
		}elseif($entryname != "." and $entryname!=".."){
			unlink("$dir/$entryname");
		}
	}
	closedir($current_dir);
	rmdir($dir);
} 

function ClearDirectory($dirPath){
	if(is_dir($dirPath)){
		$ls = DirectoryRead($dirPath);
		foreach ($ls as $file){
			if(is_dir($dirPath."/".$file))
				deldir($dirPath."/".$file);
			else 
				unlink($dirPath."/".$file);
		}
	}
}

?>
Return current item: WebSecurityTester