Jump to content

Recommended Posts

Hi ..  I am trying to list all the files and folders in a  specified root folder ..
can  u please help ?
I am trying to do it since some days now and getting errors ..

Previous programs could get the files in a folder but couldnt open a subfolder. Nw this one opens a subfolder But only two step down

Can someone help with a better alternative ?
[code]
<?php
chdir('D:\Myvideo');
$scanthis = getcwd();
scan_dir($scanthis);
function scan_dir($scanthis)
{ $dir = @opendir($scanthis);
while (false!=($file = @readdir($dir))) {
if ($file != "." && $file != "..") {
$type = filetype($file);
echo "<br>file is $file and it is a $type <br>";
if($type == "dir" )
{
$scanthisdir = $scanthis . "/" . $file;
print "<br><b>this is $scanthisdir for the subfolder</b><br>";
scan_subdir($scanthisdir);
}

}
}
}

function scan_subdir($scanthisdir)
{
$dir = @opendir($scanthisdir);
while (false!=($file = @readdir($dir))) {
if ($file != "." && $file != "..") {

$type = filetype($file);
echo "<br>file is $file and it is a $type <br>";
if($type == "dir" )
{
$scanthisdir = $scanthisdir . "/". $file;
print "<br><b>this is $scanthisdir new for the subfolder</b><br>";
scan_subdir($scanthisdir);
}

counter();

}
}
}
?>[/code]
PS :  i am only 10 days old with PhP .. so its not at all professional !!! Help
Link to comment
https://forums.phpfreaks.com/topic/29591-cannot-go-into-a-subdirectory/
Share on other sites

scandir is PHP5 and higher, but you can use this snippet to ensure that it exists (from PHP manual comments): [code]<?php
if(!function_exists('scandir')) {
  function scandir($dir, $sortorder = 0) {
      if(is_dir($dir))        {
          $dirlist = opendir($dir);
          while( ($file = readdir($dirlist)) !== false) {
              if(!is_dir($file)) {
                  $files[] = $file;
              }
          }
          ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort
          return $files;
      } else {
      return FALSE;
      break;
      }
  }
}
?>[/code]
[quote author=Daniel0 link=topic=117494.msg479399#msg479399 date=1165364208]
scandir is PHP5 and higher, but you can use this snippet to ensure that it exists (from PHP manual comments): [code]<?php
if(!function_exists('scandir')) {
  function scandir($dir, $sortorder = 0) {
      if(is_dir($dir))        {
          $dirlist = opendir($dir);
          while( ($file = readdir($dirlist)) !== false) {
              if(!is_dir($file)) {
                  $files[] = $file;
              }
          }
          ($sortorder == 0) ? asort($files) : rsort($files); // arsort was replaced with rsort
          return $files;
      } else {
      return FALSE;
      break;
      }
  }
}
?>[/code]
[/quote]

This returns me nothing ..  I also  set $dir = getcwd()
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.