views:

146

answers:

5

I have a folder structure like this:

/articles
     .index.php
     .second.php
     .third.php
     .fourth.php

If I'm writing my code in second.php, how can I scan the current folder(articles)?

Thanks

+5  A: 
$files = glob(dirname(__FILE__) . "/*.php");

http://php.net/manual/en/function.glob.php

stereofrog
+1  A: 

It depends on what you mean by 'scan' I'm assuming you want to do something like this:

$dir_handle = opendir(".");

 while($file = readdir($dir_handle)){
      //do stuff with $file
 }
GSto
this is great too ;) thanks guys
kmunky
+2  A: 

From the PHP manual:

$dir = new DirectoryIterator(dirname($path));
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot()) {
        var_dump($fileinfo->getFilename());
    }
}
dnagirl
+2  A: 
<?php

$path = new DirectoryIterator('/articles');

foreach ($path as $file) {
    echo $file->getFilename() . "\t";
    echo $file->getSize() . "\t";
    echo $file->getOwner() . "\t";
    echo $file->getMTime() . "\n";
}

?>

From The Standard PHP Library (SPL)

lo_fye
A: 
foreach (scandir('.') as $file)
    echo $file . "\n";
David Barnes