We help IT Professionals succeed at work.
Get Started

place all files in a directory in array.

dplinnane
dplinnane asked
on
418 Views
Last Modified: 2013-12-13
I have the following function it prints out all my files in each directory. How can I place the files in one array.
Every time the directory changes the counter $i is reset to zero so the previous array is written over.
I want to be able to place each variable in its own array.
$file_mod_time[$i]
$win_file_dir[$i]
so that I can insert it into a database.

Any suggestions.
Thanks.

function util_file_dir_stats ($path)
      {
         
      if ($dir=@opendir($path))
            {//OUTER IF
                     
            while (($dir_files=readdir($dir))!== false)
                  {//START WHILE
   
                  if (is_dir($path.$dir_files) AND $dir_files!= "." AND $dir_files!= "..")
                        {
                //Places all Directory names in $recurse_dir
                if ($dir_files == strtolower($dir_files))
                              {
             
                        $i++;
                        $recurse_dir[$i] = util_file_dir_stats($path.$dir_files);
               
                    }
                }

                  elseif($dir_files!= "." AND $dir_files!= "..")
                        {//IF 1
               
                        if ((preg_match("/.php/",$dir_files,$array) ))
                              {
                                                                                $i++;
                              $recurse_dir[$i] = $dir_files;
                              
                                                                                $win_file_dir[$i]  = "$path/$recurse_dir[$i]";
                              $win_file_dir[$i]  =  str_replace('//','/',$win_file_dir[$i]);
                              $file_mod_time[$i] = filemtime($win_file_dir[$i]);
                                     
                              print "$file_mod_time[$i] $win_file_dir[$i] ".'<BR>';
                   
                                                                                 }
                                       
                              }//END IF 1
                   
                  }//END WHILE          
               
            closedir($dir);
       
            }//END OUTER IF
      return($array);
      }
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE