TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 09-26-2009, 12:46 PM   #1 (permalink)
The Contributor
 
Join Date: Apr 2008
Posts: 78
Thanks: 0
benton is on a distinguished road
Default Glob recursion not working right

I need to be able to read through all directories in a given path and list all of the files. I'm using the following code and it works for the top level but not sub-directories. For example, if there is this structure
Code:
dirA
 dirB
  fileB 
 fileA
If will enter into dirA and display fileA. It will also show that it is going into the sub-directory dirB but fileB is never listed. Would someone please point out what I'm missing or let me know if there is a better way to do this?

PHP Code:
function GetAllFiles(&$files$locn)
{
  
$dirs glob($locn '/*'GLOB_ONLYDIR);
   
  if(
is_array($dirs) && count($dirs) > 0)
  {
    foreach (
$dirs as $dir)
    {
      
$cwd getcwd();
      
chdir ($dir);      
      
      foreach (
glob("*") as $filename
      {
         if (
is_dir($filename))
         {
           echo 
'enter subdir '.$filename.'<br>';
           
GetAllFiles($files$dir '/'.$filename);
         }  
               
         echo 
'file '.$filename .'<br>';
         
$files[] = $filename;
      }
       
chdir ($cwd); 
    }
  }

benton is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Categories and sub categories - recursion Dinky Advanced PHP Programming 2 02-01-2010 07:45 PM
Wamp working, but what next? Help! DotNetTim Absolute Beginners 3 02-07-2009 10:05 AM
Mod Rewrite only partially working Gareth General 6 12-24-2008 06:08 PM
Traverse Directories the Easy Way with Glob() ! Wildhoney Absolute Beginners 6 12-02-2008 11:07 PM
Exec(zip) in PHP not working as expected oscargodson General 3 09-28-2008 12:00 PM


All times are GMT. The time now is 05:59 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design