I have a script which runs through the directories in a folder (on windows machine) and outputs a link to all the files in the directories.
My directory structure is normally something like:
2002
2003
2004
2005
Corres
Misc
What I need to do is output the directories in a different ORDER, so that it is reverse numeric order, then alpha. So that the script will output:
2005
2004
2003
2003
Corres
Misc
A further enhancment might be to do the last two years, then alpha, then rest:
2005
2004
Corres
Misc
2003
2002
Any help would be really appreciated.
[script]
function CreateLinkToOfficeFile($dir)
{
chdir($dir);
if(!($dp = opendir($dir))) die ("Cannot open $dir");
while($file = readdir($dp))
{
if(is_dir($file))
{
if($file != '.' && $file != '..')
{
echo "<h4>$file</h4><br>\n";
echo "\t<ul>\n";
CreateLinkToOfficeFile("$dir/$file");
chdir($dir);
echo "\t</ul>\n";
}
}
else
{
if($file != '.' && $file != '..')
{
$ext = strtolower(str_replace('.','',strstr($file, '.')));
if(($ext=="doc"||$ext=="dot"||$ext=="xls"||$ext=="xlt"||$ext=="pdf"||$ext=="csv"||$ext=="tif"||$ext=="tiff") && preg_match("/[~$]/", $file) != true)
{
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> <tr valign=\"middle\">\n";
echo "<td width=\"5%\"><img src=\"images/$ext.gif\" alt=\"$ext\" width=25 height=25></td><td width=\"45%\"><a href=\"$dir/$file\" target=\"_blank\">$file</a></td>\n";
echo "<td width=\"50%\"\n>";
echo "</td>\n";
echo "</tr>\n";
echo " </table>\n";
}
}
}
}
closedir($dp);
}
[/script]
My directory structure is normally something like:
2002
2003
2004
2005
Corres
Misc
What I need to do is output the directories in a different ORDER, so that it is reverse numeric order, then alpha. So that the script will output:
2005
2004
2003
2003
Corres
Misc
A further enhancment might be to do the last two years, then alpha, then rest:
2005
2004
Corres
Misc
2003
2002
Any help would be really appreciated.
[script]
function CreateLinkToOfficeFile($dir)
{
chdir($dir);
if(!($dp = opendir($dir))) die ("Cannot open $dir");
while($file = readdir($dp))
{
if(is_dir($file))
{
if($file != '.' && $file != '..')
{
echo "<h4>$file</h4><br>\n";
echo "\t<ul>\n";
CreateLinkToOfficeFile("$dir/$file");
chdir($dir);
echo "\t</ul>\n";
}
}
else
{
if($file != '.' && $file != '..')
{
$ext = strtolower(str_replace('.','',strstr($file, '.')));
if(($ext=="doc"||$ext=="dot"||$ext=="xls"||$ext=="xlt"||$ext=="pdf"||$ext=="csv"||$ext=="tif"||$ext=="tiff") && preg_match("/[~$]/", $file) != true)
{
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> <tr valign=\"middle\">\n";
echo "<td width=\"5%\"><img src=\"images/$ext.gif\" alt=\"$ext\" width=25 height=25></td><td width=\"45%\"><a href=\"$dir/$file\" target=\"_blank\">$file</a></td>\n";
echo "<td width=\"50%\"\n>";
echo "</td>\n";
echo "</tr>\n";
echo " </table>\n";
}
}
}
}
closedir($dp);
}
[/script]