help with the subdir listing and sorting by date
Posted: Sun Mar 28, 2010 12:08 pm
I am trying to write a code to list the all subdir of the main path directories and also sort them by date ... i search the net and came up with this code :
its doing the job perfectly, but there is 2 major problems :
1- it also lists the main directories ($Pathc directories)
.
2- the current sorting is descending, i can't change it to ascending.
also if possible i want to link the list items to $path/$file...
thanks in advance
Code: Select all
<?
$t = 0;
$f = 0;
$dir_name = array();
$dir_time = array();
$pathc = "$pathc";
$dir_handle = @opendir($pathc) or die("Unable to open $pathc");
while ($list = readdir($dir_handle)) {
if ($list != "." && $list != ".." && $list != "index.php~") {
while ($list = readdir($dir_handle)) {
$path = "$pathc/$list";
if (@$handle = opendir($path)) {
while ($file = readdir($handle)) {
if($file != "." && $file != ".." && $file != "index.php~") {
$fName = $file;
$files = $path.'/'.$file;
if(false== is_file($file)){
$dir_time[$t++] = filemtime($files);
$dir_name[$f++] = $file;
}
}
}
closedir($handle);
}
}
closedir($dir_handle);
}
asort( $dir_time);
asort( $dir_name);
}
foreach ($dir_time as $key=>$ftime){
$fname = $dir_name[$key];
echo $fname.'<br/>';
}?>
1- it also lists the main directories ($Pathc directories)
2- the current sorting is descending, i can't change it to ascending.
also if possible i want to link the list items to $path/$file...
thanks in advance