I have looked at the PHP file system commands, and I cannot see a function that would return an array of file names contained in a target directory.
A list of filenames i.e. ls on unix, or dir on windows.
Any advice would be greatly appreciated.
Thank you
- Dickey
File Ops: An array containing file names within a directory
Moderator: General Moderators
http://www.php.net/manual/en/function.readdir.php
not returning an array of filenames but you will be able to create one.
also note http://www.php.net/manual/en/function.is-dir.php
not returning an array of filenames but you will be able to create one.
also note http://www.php.net/manual/en/function.is-dir.php
I'm feeling nice... 
Per example 2 on http://www.php.net/manual/en/function.readdir.php this function will create an associative array of files in alphabetical order from a given directory.
Per example 2 on http://www.php.net/manual/en/function.readdir.php this function will create an associative array of files in alphabetical order from a given directory.
Code: Select all
<?php
function getFileList($theDIR) {
$fileArray = array();
if($handle = opendir($theDIR)) {
while(false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
if(@is_file($theDIR . "/" . $file)) {
$fileArrayї$file] = $theDIR . "/" . $file;
}
}
}
closedir($handle);
}
asort($fileArray);
reset($fileArray);
return $fileArray;
}
$fileListArray = getFileList("/path/to/dir");
?>