function to grab file name from a folder
Moderator: General Moderators
function to grab file name from a folder
Im looking for a function or a way to grab all the file names in a certain folder and chuck them into an array, does any one know how to do this.
-
SKDevelopment
- Forum Newbie
- Posts: 13
- Joined: Thu Jan 26, 2006 10:42 am
It would be something like this.
The array $a will contain all the file names in the folder $directory.
--
Best Regards,
Sergey Korolev
www.SKDevelopment.com
Code: Select all
$directory = "directory1"; // directory name
$dir = opendir($directory);
while(($file = readdir($dir)))
{
if(is_file($directory.'/'.$file))
{
$a[] = $file;
}
} // end while
closedir($dir);
// $a containes all the file names in the direstory
echo "<pre>"; print_r($a); echo "</pre>";--
Best Regards,
Sergey Korolev
www.SKDevelopment.com