I want to write a simple page which will read the contents of a folder and returns or displays all the .doc or .pdf or .wpd files in the folder -- sorted alphabetically and numerically.
Can anyone help me with the code?
Thanks!
Joe
Sorting/Displaying the contents of a folder
Moderator: General Moderators
more info (if it helps)
Here it what I have already. It works in that it displays all the documents in the folder but the sorting it off...
My code is:
A portion of my results is:
While the names of the files may not make sense to you, why would 20050066 appear to be out of sequence??
My code is:
Code: Select all
$regexp = '\.(doc|wpd|dot)$';
// For every additional extension, just add the extension, like exe would be put in like
// (doc|wpd|exe)
$dir = "../Projectform";
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && ereg($regexp, $file)) {
// split the file name in 2 parts (one before and one after the dot)
$fileparts = explode(".",$file);
echo "<a href=\"" . $dir . "/" . $file . "\">" . $fileparts[0] . "</a><br />\n";
}
}
closedir($handle);
}Code: Select all
20010016- 1997-98_NonEmployerSurvey
20020017-Research_LogEvalSoftware
20050066-M3_IVR
20020018-EconDrillDownApp
20020019-DirectoryInterProbSolvingEnviron-
dyonak
- Forum Commoner
- Posts: 56
- Joined: Wed Jun 22, 2005 10:22 am
- Location: Minneapolis, MN
- Contact:
Glob would work well for what you need. This is untested, let me know if you have problems.
alphabetical results:
reverse alphabetical results:
alphabetical results:
Code: Select all
$Results = glob("{*.pdf,*.doc,*.wpd}", GLOB_BRACE);
sort( $Results );
print_r ($Results);Code: Select all
$Results = glob("{*.pdf,*.doc,*.wpd}", GLOB_BRACE);
sort( $Results );
print_r ($Results);I simply cut and pasted your suggestion and got these errors:
and
Am I missing something? (I am a php-dunce.)
Thanks.
Code: Select all
Warning: glob() expects parameter 2 to be long, string givenCode: Select all
sort() expects parameter 1 to be array, null givenThanks.