Re: [PHP] Re: Directory Listing

2009-08-26 Thread Ashley Sheridan
On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
 I've been playing about more and now I have the following code:
 
 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 
 function getDirectory($path = '.', $ignore = '') {
 $dirTree = array ();
 $dirTreeTemp = array ();
 $fileDate = array ();
 $ignore[] = '.';
 $ignore[] = '..';
 $dh = @opendir($path);
 while (false !== ($file = readdir($dh))) {
 if (!in_array($file, $ignore)) {
 if (!is_dir($path/$file)) {
 $dirTree[$path][] = $file;
 $fileDate[$file][] = date (d/m/Y,
 filemtime($path/$file));
 } else {
 $dirTreeTemp = getDirectory($path/$file, $ignore);
 if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp, $fileDate);
 }
 }
 }
 closedir($dh);
 return $dirTree;
 }
 
 $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
 $dirTree = getDirectory('.', $ignore);
 getdirectory('.');
 
 echo Gatwick Tender Documents\n;
 
 foreach( $dirTree as $key = $folder ){
echo \n; //Don't need folders as they're shown with the files
foreach( $folder as $file){
echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
 out with a tab for easy import into excel
 
}
 }
 print_r($dirTree); //Just using this for debugging
 ?
 
 
 The output is fine for the paths and filenames but I still can't get
 the dates showing. It's getting the correct date for some but not all.
 I did something else earlier and found that all the dates were
 01/01/1970 but at least there was a date for every file but can't
 remember how I go there!
 
 
 Here is a sample output result:
 
 Gatwick Tender Documents
 
 . 9216_100_REV_V1.0_bound.dwg 
 
 Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf 
 Tender Docs   Contents of Volumes 1 and 2.pdf 
 Tender Docs   Cover Letter and Instructions.doc   
 Tender Docs   Form of Tender.doc  
 
 Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
 Questionaire rev2.xls
 
 BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009  
 
 Contents of Volumes 1 and 2.pdf   29/07/2009  
 
 Cover Letter and Instructions.doc 29/07/2009  
 
 Form of Tender.doc29/07/2009  
 
 Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls  
 Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls 
 Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls 
 Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls 
 Tender Docs/NTB BH Lighting   3J-D PIR.xls
 Tender Docs/NTB BH Lighting   4G-G PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls 
 Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls 
 Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls 
 Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls 
 Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls  
 Tender Docs/NTB BH Lighting   5G-G PIR.xls
 
 
 Can anyone shed any light on it?
 I'm about to admit defeat!
 
 Thanks in advance and I'm not being lazy - I really am trying!!! :(
 
 Tom
 

The only time I've ever noticed this problem was on a 32bit system where
the files were above 2GB each. When the files are that size, none of the
information functions seem to work correctly, including the filesize,
date, etc.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Tom Chubb
2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
 I've been playing about more and now I have the following code:

 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);

 function getDirectory($path = '.', $ignore = '') {
     $dirTree = array ();
     $dirTreeTemp = array ();
     $fileDate = array ();
     $ignore[] = '.';
     $ignore[] = '..';
     $dh = @opendir($path);
     while (false !== ($file = readdir($dh))) {
         if (!in_array($file, $ignore)) {
             if (!is_dir($path/$file)) {
                 $dirTree[$path][] = $file;
                 $fileDate[$file][] = date (d/m/Y,
 filemtime($path/$file));
             } else {
                 $dirTreeTemp = getDirectory($path/$file, $ignore);
                 if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp, $fileDate);
             }
         }
     }
     closedir($dh);
     return $dirTree;
 }

 $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
 $dirTree = getDirectory('.', $ignore);
 getdirectory('.');

 echo Gatwick Tender Documents\n;

 foreach( $dirTree as $key = $folder ){
    echo \n; //Don't need folders as they're shown with the files
    foreach( $folder as $file){
        echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
 out with a tab for easy import into excel

    }
 }
 print_r($dirTree); //Just using this for debugging
 ?


 The output is fine for the paths and filenames but I still can't get
 the dates showing. It's getting the correct date for some but not all.
 I did something else earlier and found that all the dates were
 01/01/1970 but at least there was a date for every file but can't
 remember how I go there!


 Here is a sample output result:

 Gatwick Tender Documents

 .     9216_100_REV_V1.0_bound.dwg

 Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
 Tender Docs   Contents of Volumes 1 and 2.pdf
 Tender Docs   Cover Letter and Instructions.doc
 Tender Docs   Form of Tender.doc

 Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
 Questionaire rev2.xls

 BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009

 Contents of Volumes 1 and 2.pdf       29/07/2009

 Cover Letter and Instructions.doc     29/07/2009

 Form of Tender.doc    29/07/2009

 Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls
 Tender Docs/NTB BH Lighting   3J-D PIR.xls
 Tender Docs/NTB BH Lighting   4G-G PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls
 Tender Docs/NTB BH Lighting   5G-G PIR.xls


 Can anyone shed any light on it?
 I'm about to admit defeat!

 Thanks in advance and I'm not being lazy - I really am trying!!! :(

 Tom


 The only time I've ever noticed this problem was on a 32bit system where
 the files were above 2GB each. When the files are that size, none of the
 information functions seem to work correctly, including the filesize,
 date, etc.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Cheers Ash,
I read that too, but I was getting the error for over 90% of the files
which I know are generally only a few MB.
I've started from scratch again and come up with something that is
easier to deal with but still having one last problem!

?php
error_reporting(E_ALL);
ini_set('display_errors', true);
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file !=index.php  $file != .  $file != 
..) {
if (is_dir($directory. / . $file)) {
//For Directories
if($recursive) {
$array_items = 
array_merge($array_items,
directoryToArray($directory. / . $file, $recursive));
}
$fullfile = $directory . / . $file;
$array_items[] = 
preg_replace(/\/\//si, /, $fullfile);
} else {
//For Files
$fullfile = $directory . / . $file;
$array_items[] = 
preg_replace(/\/\//si, /, $fullfile);
}
}
}
closedir($handle);
}
return $array_items;
}

$files = directoryToArray(./Tender, true);


//Output to browser
foreach ($files as $file) {
echo str_replace(./Tender, , $file) . \t .. date 
(d/m/Y,
filemtime($file)) . \n;

Re: [PHP] Re: Directory Listing

2009-08-26 Thread Ashley Sheridan
On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote:
 2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:
  On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
  I've been playing about more and now I have the following code:
 
  ?
  error_reporting(E_ALL);
  ini_set('display_errors', true);
 
  function getDirectory($path = '.', $ignore = '') {
  $dirTree = array ();
  $dirTreeTemp = array ();
  $fileDate = array ();
  $ignore[] = '.';
  $ignore[] = '..';
  $dh = @opendir($path);
  while (false !== ($file = readdir($dh))) {
  if (!in_array($file, $ignore)) {
  if (!is_dir($path/$file)) {
  $dirTree[$path][] = $file;
  $fileDate[$file][] = date (d/m/Y,
  filemtime($path/$file));
  } else {
  $dirTreeTemp = getDirectory($path/$file, $ignore);
  if (is_array($dirTreeTemp))$dirTree =
  array_merge($dirTree, $dirTreeTemp, $fileDate);
  }
  }
  }
  closedir($dh);
  return $dirTree;
  }
 
  $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
  $dirTree = getDirectory('.', $ignore);
  getdirectory('.');
 
  echo Gatwick Tender Documents\n;
 
  foreach( $dirTree as $key = $folder ){
 echo \n; //Don't need folders as they're shown with the files
 foreach( $folder as $file){
 echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
  out with a tab for easy import into excel
 
 }
  }
  print_r($dirTree); //Just using this for debugging
  ?
 
 
  The output is fine for the paths and filenames but I still can't get
  the dates showing. It's getting the correct date for some but not all.
  I did something else earlier and found that all the dates were
  01/01/1970 but at least there was a date for every file but can't
  remember how I go there!
 
 
  Here is a sample output result:
 
  Gatwick Tender Documents
 
  . 9216_100_REV_V1.0_bound.dwg
 
  Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
  Tender Docs   Contents of Volumes 1 and 2.pdf
  Tender Docs   Cover Letter and Instructions.doc
  Tender Docs   Form of Tender.doc
 
  Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
  Questionaire rev2.xls
 
  BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009
 
  Contents of Volumes 1 and 2.pdf   29/07/2009
 
  Cover Letter and Instructions.doc 29/07/2009
 
  Form of Tender.doc29/07/2009
 
  Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls
  Tender Docs/NTB BH Lighting   3J-D PIR.xls
  Tender Docs/NTB BH Lighting   4G-G PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls
  Tender Docs/NTB BH Lighting   5G-G PIR.xls
 
 
  Can anyone shed any light on it?
  I'm about to admit defeat!
 
  Thanks in advance and I'm not being lazy - I really am trying!!! :(
 
  Tom
 
 
  The only time I've ever noticed this problem was on a 32bit system where
  the files were above 2GB each. When the files are that size, none of the
  information functions seem to work correctly, including the filesize,
  date, etc.
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 
 
 
 Cheers Ash,
 I read that too, but I was getting the error for over 90% of the files
 which I know are generally only a few MB.
 I've started from scratch again and come up with something that is
 easier to deal with but still having one last problem!
 
 ?php
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function directoryToArray($directory, $recursive) {
   $array_items = array();
   if ($handle = opendir($directory)) {
   while (false !== ($file = readdir($handle))) {
   if ($file !=index.php  $file != .  $file != 
 ..) {
   if (is_dir($directory. / . $file)) {
   //For Directories
   if($recursive) {
   $array_items = 
 array_merge($array_items,
 directoryToArray($directory. / . $file, $recursive));
   }
   $fullfile = $directory . / . $file;
   $array_items[] = 
 preg_replace(/\/\//si, /, $fullfile);
   } else {
   //For Files
   $fullfile = $directory . / . $file;
   $array_items[] = 
 preg_replace(/\/\//si, /, $fullfile);
   }
   }
   }
   closedir($handle);
   }
   return $array_items;
 }
 
 $files = 

Re: [PHP] Re: Directory Listing

2009-08-26 Thread Tom Chubb
2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote:
 2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:
  On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
  I've been playing about more and now I have the following code:
 
  ?
  error_reporting(E_ALL);
  ini_set('display_errors', true);
 
  function getDirectory($path = '.', $ignore = '') {
      $dirTree = array ();
      $dirTreeTemp = array ();
      $fileDate = array ();
      $ignore[] = '.';
      $ignore[] = '..';
      $dh = @opendir($path);
      while (false !== ($file = readdir($dh))) {
          if (!in_array($file, $ignore)) {
              if (!is_dir($path/$file)) {
                  $dirTree[$path][] = $file;
                  $fileDate[$file][] = date (d/m/Y,
  filemtime($path/$file));
              } else {
                  $dirTreeTemp = getDirectory($path/$file, $ignore);
                  if (is_array($dirTreeTemp))$dirTree =
  array_merge($dirTree, $dirTreeTemp, $fileDate);
              }
          }
      }
      closedir($dh);
      return $dirTree;
  }
 
  $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
  $dirTree = getDirectory('.', $ignore);
  getdirectory('.');
 
  echo Gatwick Tender Documents\n;
 
  foreach( $dirTree as $key = $folder ){
     echo \n; //Don't need folders as they're shown with the files
     foreach( $folder as $file){
         echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
  out with a tab for easy import into excel
 
     }
  }
  print_r($dirTree); //Just using this for debugging
  ?
 
 
  The output is fine for the paths and filenames but I still can't get
  the dates showing. It's getting the correct date for some but not all.
  I did something else earlier and found that all the dates were
  01/01/1970 but at least there was a date for every file but can't
  remember how I go there!
 
 
  Here is a sample output result:
 
  Gatwick Tender Documents
 
  .     9216_100_REV_V1.0_bound.dwg
 
  Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
  Tender Docs   Contents of Volumes 1 and 2.pdf
  Tender Docs   Cover Letter and Instructions.doc
  Tender Docs   Form of Tender.doc
 
  Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
  Questionaire rev2.xls
 
  BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009
 
  Contents of Volumes 1 and 2.pdf       29/07/2009
 
  Cover Letter and Instructions.doc     29/07/2009
 
  Form of Tender.doc    29/07/2009
 
  Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls
  Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls
  Tender Docs/NTB BH Lighting   3J-D PIR.xls
  Tender Docs/NTB BH Lighting   4G-G PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls
  Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls
  Tender Docs/NTB BH Lighting   5G-G PIR.xls
 
 
  Can anyone shed any light on it?
  I'm about to admit defeat!
 
  Thanks in advance and I'm not being lazy - I really am trying!!! :(
 
  Tom
 
 
  The only time I've ever noticed this problem was on a 32bit system where
  the files were above 2GB each. When the files are that size, none of the
  information functions seem to work correctly, including the filesize,
  date, etc.
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 
 

 Cheers Ash,
 I read that too, but I was getting the error for over 90% of the files
 which I know are generally only a few MB.
 I've started from scratch again and come up with something that is
 easier to deal with but still having one last problem!

 ?php
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function directoryToArray($directory, $recursive) {
       $array_items = array();
       if ($handle = opendir($directory)) {
               while (false !== ($file = readdir($handle))) {
                       if ($file !=index.php  $file != .  $file != 
 ..) {
                               if (is_dir($directory. / . $file)) {
                                       //For Directories
                                       if($recursive) {
                                               $array_items = 
 array_merge($array_items,
 directoryToArray($directory. / . $file, $recursive));
                                       }
                                       $fullfile = $directory . / . $file;
                                       $array_items[] = 
 preg_replace(/\/\//si, /, $fullfile);
                               } else {
                                       //For Files
                                       $fullfile = $directory . / . $file;
                                       $array_items[] = 
 preg_replace(/\/\//si, /, $fullfile);
                               }
                       }
               }
               closedir($handle);
       }
       

Re: [PHP] Re: Directory Listing

2009-08-26 Thread hack988 hack988
have a tab inserted in the middle of the path ??? What it mean,I
can't find any diffrent between last one with other rows.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Ashley Sheridan
On Wed, 2009-08-26 at 18:21 +0800, hack988 hack988 wrote:
 have a tab inserted in the middle of the path ??? What it mean,I
 can't find any diffrent between last one with other rows.
 
It might be because of the way that the mailing list software converts
the content?

I tend to always make CSV files comma delimited, as it's easier on the
eye to open a file up in a ext editor and hack away at it, and you have
the benefit of being able to use other whitespace characters (tabs,
spaces, etc) to line up field data (although field values should really
be enclosed in quotation marks if you go down this route just in-case)

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Tom Chubb
2009/8/26 hack988 hack988 hack...@dev.htwap.com:
 have a tab inserted in the middle of the path ??? What it mean,I
 can't find any diffrent between last one with other rows.


To clarify - this is what I was getting:

/tab here9216_100_REV_V1.0_bound.dwgtab here05/08/2009
/Tender Docs/tab hereBAA Works Terms v1.1 (22.05.08).pdftab
here29/07/2009
/Tender Docs/UNWANTED TAB HEREHealth and Safety Questionnaire 14/08/2009

-- 
Tom Chubb
t...@tomchubb.com | tomch...@gmail.com
07912 202846

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Tom Chubb
2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Wed, 2009-08-26 at 18:21 +0800, hack988 hack988 wrote:
 have a tab inserted in the middle of the path ??? What it mean,I
 can't find any diffrent between last one with other rows.

 It might be because of the way that the mailing list software converts
 the content?

 I tend to always make CSV files comma delimited, as it's easier on the
 eye to open a file up in a ext editor and hack away at it, and you have
 the benefit of being able to use other whitespace characters (tabs,
 spaces, etc) to line up field data (although field values should really
 be enclosed in quotation marks if you go down this route just in-case)

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Thanks Ash,
I've learnt quite a lot trying to get this working!
And yeah I think I might change it to csv now.

-- 
Tom Chubb
t...@tomchubb.com | tomch...@gmail.com
07912 202846

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread hack988 hack988
your means Health and Safety Questionnaireis directory?
so you want it display like this
full dir path tab filenametabdate

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Tom Chubb
2009/8/26 hack988 hack988 hack...@dev.htwap.com:
 your means Health and Safety Questionnaireis directory?
 so you want it display like this
 full dir path tab filenametabdate


Yes.
I did try using if(is_dir($file)) { insert tab } but couldn't get it to work.
Also tried counting the length of the $file value and and comparing it
to the position of the first / using strpos and if they matched then
assume it was a directory but couldn't get it to work either.

Out of the 2000 files there are less than 50 directories so it wasn't
too much trouble to go through and sort them out manually but I'd love
to hear a way of doing it properly

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Eddie Drapkin
On Wed, Aug 26, 2009 at 9:45 AM, hack988 hack988hack...@dev.htwap.com wrote:
 I'm write a php file for you
 =
 define('Line_End', (PHP_OS == 'WINNT')?\r\n:\n);
 clearstatcache();

 $mylist=array();
 listdir(F:\\Programming\\Web\\php,$mylist);
 function listdir($dir,$list){
  if ($handle = opendir( $dir )){
   while ( false !== ( $item = readdir( $handle ) ) ) {
     if ( $item != .  $item != .. ) {
           $item=str_replace(Line_End,,$item);
       if ( is_dir( $dir.DIRECTORY_SEPARATOR.$item ) ) {
         listdir($dir.DIRECTORY_SEPARATOR.$item, $list);
       } else {
         $list[]=$dir.DIRECTORY_SEPARATOR.\t.$item.\t.date(m/d/Y,
 filemtime($dir.DIRECTORY_SEPARATOR.$item));
       }
     }
   }
   closedir( $handle );
  }
 }
 var_dump($mylist);

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



Why manually define Line_End when PHP_EOL already exists?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread hack988 hack988
some code copy from my old codes for truncatedir function,it for
backend compatibility.
see this
PHP_EOL (string)
Available since PHP 4.3.10 and PHP 5.0.2

http://cn.php.net/manual/en/reserved.constants.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread hack988 hack988
I'm write a php file for you
=
define('Line_End', (PHP_OS == 'WINNT')?\r\n:\n);
clearstatcache();

$mylist=array();
listdir(F:\\Programming\\Web\\php,$mylist);
function listdir($dir,$list){
  if ($handle = opendir( $dir )){
   while ( false !== ( $item = readdir( $handle ) ) ) {
 if ( $item != .  $item != .. ) {
   $item=str_replace(Line_End,,$item);
   if ( is_dir( $dir.DIRECTORY_SEPARATOR.$item ) ) {
 listdir($dir.DIRECTORY_SEPARATOR.$item, $list);
   } else {
 $list[]=$dir.DIRECTORY_SEPARATOR.\t.$item.\t.date(m/d/Y,
filemtime($dir.DIRECTORY_SEPARATOR.$item));
   }
 }
   }
   closedir( $handle );
  }
}
var_dump($mylist);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-26 Thread Steve

Ashley Sheridan wrote:

On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote:
  

2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:


On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:
  

I've been playing about more and now I have the following code:

?
error_reporting(E_ALL);
ini_set('display_errors', true);

function getDirectory($path = '.', $ignore = '') {
$dirTree = array ();
$dirTreeTemp = array ();
$fileDate = array ();
$ignore[] = '.';
$ignore[] = '..';
$dh = @opendir($path);
while (false !== ($file = readdir($dh))) {
if (!in_array($file, $ignore)) {
if (!is_dir($path/$file)) {
$dirTree[$path][] = $file;
$fileDate[$file][] = date (d/m/Y,
filemtime($path/$file));
} else {
$dirTreeTemp = getDirectory($path/$file, $ignore);
if (is_array($dirTreeTemp))$dirTree =
array_merge($dirTree, $dirTreeTemp, $fileDate);
}
}
}
closedir($dh);
return $dirTree;
}

$ignore = array('.htaccess', 'Thumbs.db', 'index.php');
$dirTree = getDirectory('.', $ignore);
getdirectory('.');

echo Gatwick Tender Documents\n;

foreach( $dirTree as $key = $folder ){
   echo \n; //Don't need folders as they're shown with the files
   foreach( $folder as $file){
   echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
out with a tab for easy import into excel

   }
}
print_r($dirTree); //Just using this for debugging
?


The output is fine for the paths and filenames but I still can't get
the dates showing. It's getting the correct date for some but not all.
I did something else earlier and found that all the dates were
01/01/1970 but at least there was a date for every file but can't
remember how I go there!


Here is a sample output result:

Gatwick Tender Documents

. 9216_100_REV_V1.0_bound.dwg

Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
Tender Docs   Contents of Volumes 1 and 2.pdf
Tender Docs   Cover Letter and Instructions.doc
Tender Docs   Form of Tender.doc

Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
Questionaire rev2.xls

BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009

Contents of Volumes 1 and 2.pdf   29/07/2009

Cover Letter and Instructions.doc 29/07/2009

Form of Tender.doc29/07/2009

Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls
Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls
Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls
Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls
Tender Docs/NTB BH Lighting   3J-D PIR.xls
Tender Docs/NTB BH Lighting   4G-G PIR.xls
Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls
Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls
Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls
Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls
Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls
Tender Docs/NTB BH Lighting   5G-G PIR.xls


Can anyone shed any light on it?
I'm about to admit defeat!

Thanks in advance and I'm not being lazy - I really am trying!!! :(

Tom



The only time I've ever noticed this problem was on a 32bit system where
the files were above 2GB each. When the files are that size, none of the
information functions seem to work correctly, including the filesize,
date, etc.

Thanks,
Ash
http://www.ashleysheridan.co.uk




  

Cheers Ash,
I read that too, but I was getting the error for over 90% of the files
which I know are generally only a few MB.
I've started from scratch again and come up with something that is
easier to deal with but still having one last problem!

?php
error_reporting(E_ALL);
ini_set('display_errors', true);
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file !=index.php  $file != .  $file != 
..) {
if (is_dir($directory. / . $file)) {
//For Directories
if($recursive) {
$array_items = 
array_merge($array_items,
directoryToArray($directory. / . $file, $recursive));
}
$fullfile = $directory . / . $file;
$array_items[] = preg_replace(/\/\//si, 
/, $fullfile);
} else {
//For Files
$fullfile = $directory . / . $file;
$array_items[] = preg_replace(/\/\//si, 
/, $fullfile);
}
}
}
closedir($handle);
}
return $array_items;
}

$files = directoryToArray(./Tender, true);


//Output to browser
foreach ($files as $file) {
echo str_replace(./Tender, , $file) . \t . . date 

Re: [PHP] Re: Directory Listing

2009-08-26 Thread hack988 hack988
use realpath is better that i think

2009/8/26 Steve ad...@ultramegatech.com:
 Ashley Sheridan wrote:

 On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote:


 2009/8/26 Ashley Sheridan a...@ashleysheridan.co.uk:


 On Tue, 2009-08-25 at 17:08 +0100, Tom Chubb wrote:


 I've been playing about more and now I have the following code:

 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);

 function getDirectory($path = '.', $ignore = '') {
    $dirTree = array ();
    $dirTreeTemp = array ();
    $fileDate = array ();
    $ignore[] = '.';
    $ignore[] = '..';
    $dh = @opendir($path);
    while (false !== ($file = readdir($dh))) {
        if (!in_array($file, $ignore)) {
            if (!is_dir($path/$file)) {
                $dirTree[$path][] = $file;
                $fileDate[$file][] = date (d/m/Y,
 filemtime($path/$file));
            } else {
                $dirTreeTemp = getDirectory($path/$file, $ignore);
                if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp, $fileDate);
            }
        }
    }
    closedir($dh);
    return $dirTree;
 }

 $ignore = array('.htaccess', 'Thumbs.db', 'index.php');
 $dirTree = getDirectory('.', $ignore);
 getdirectory('.');

 echo Gatwick Tender Documents\n;

 foreach( $dirTree as $key = $folder ){
   echo \n; //Don't need folders as they're shown with the files
   foreach( $folder as $file){
       echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
 out with a tab for easy import into excel

   }
 }
 print_r($dirTree); //Just using this for debugging
 ?


 The output is fine for the paths and filenames but I still can't get
 the dates showing. It's getting the correct date for some but not all.
 I did something else earlier and found that all the dates were
 01/01/1970 but at least there was a date for every file but can't
 remember how I go there!


 Here is a sample output result:

 Gatwick Tender Documents

 .     9216_100_REV_V1.0_bound.dwg

 Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
 Tender Docs   Contents of Volumes 1 and 2.pdf
 Tender Docs   Cover Letter and Instructions.doc
 Tender Docs   Form of Tender.doc

 Tender Docs/Health and Safety Questionnaire   NT Baggage Tender
 Questionaire rev2.xls

 BAA Works Terms v1.1 (22.05.08).pdf   29/07/2009

 Contents of Volumes 1 and 2.pdf       29/07/2009

 Cover Letter and Instructions.doc     29/07/2009

 Form of Tender.doc    29/07/2009

 Tender Docs/NTB BH Lighting   3J-B-1 PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-2B PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-2R PIR.xls
 Tender Docs/NTB BH Lighting   3J-B-3R PIR.xls
 Tender Docs/NTB BH Lighting   3J-D PIR.xls
 Tender Docs/NTB BH Lighting   4G-G PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-1B PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-1R PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-2B PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-2R PIR.xls
 Tender Docs/NTB BH Lighting   4J-B-4 PIR.xls
 Tender Docs/NTB BH Lighting   5G-G PIR.xls


 Can anyone shed any light on it?
 I'm about to admit defeat!

 Thanks in advance and I'm not being lazy - I really am trying!!! :(

 Tom



 The only time I've ever noticed this problem was on a 32bit system where
 the files were above 2GB each. When the files are that size, none of the
 information functions seem to work correctly, including the filesize,
 date, etc.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk






 Cheers Ash,
 I read that too, but I was getting the error for over 90% of the files
 which I know are generally only a few MB.
 I've started from scratch again and come up with something that is
 easier to deal with but still having one last problem!

 ?php
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function directoryToArray($directory, $recursive) {
        $array_items = array();
        if ($handle = opendir($directory)) {
                while (false !== ($file = readdir($handle))) {
                        if ($file !=index.php  $file != .  $file
 != ..) {
                                if (is_dir($directory. / . $file)) {
                                        //For Directories
                                        if($recursive) {
                                                $array_items =
 array_merge($array_items,
 directoryToArray($directory. / . $file, $recursive));
                                        }
                                        $fullfile = $directory . / .
 $file;
                                        $array_items[] =
 preg_replace(/\/\//si, /, $fullfile);
                                } else {
                                        //For Files
                                        $fullfile = $directory . / .
 $file;
                                        $array_items[] =
 preg_replace(/\/\//si, /, $fullfile);
                                }
                        }
                }
                closedir($handle);
        }
        return $array_items;
 }

 $files = 

[PHP] Re: Directory Listing

2009-08-25 Thread Ralph Deffke
I would say
foreach( $dirTree as $key = $value ){
echo $key .br;
foreach( $value as $v){
echo $v .br;
}
}

something like that

ralph_def...@yahoo.de
Tom Chubb tomch...@gmail.com wrote in message
news:4577934f0908250241i195dc691x3f8c552e72791...@mail.gmail.com...
Hi gang,
I'm trying to create a script to read the files in a folder (approx
2000) and get the filename, path and last modified date in a tabulated
format to copy into excel. (We have been issued a CD and need to get
all files documented and assigned to an owner.)

I've tried loads of different scripts but can't get them working with
all the features.
I think the best one to work with is this (although I'm having
problems getting the date but don't worry about that at the moment)

?
error_reporting(E_ALL);
ini_set('display_errors', true);
function getDirectory($path = '.', $ignore = '') {
$dirTree = array ();
$dirTreeTemp = array ();
$ignore[] = '.';
$ignore[] = '..';

$dh = @opendir($path);

while (false !== ($file = readdir($dh))) {

if (!in_array($file, $ignore)) {
if (!is_dir($path/$file)) {

$dirTree[$path][] = $file;

} else {

$dirTreeTemp = getDirectory($path/$file, $ignore);
if (is_array($dirTreeTemp))$dirTree =
array_merge($dirTree, $dirTreeTemp);
}
}
}
closedir($dh);

return $dirTree;
}

$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
'.ftpquota');

$dirTree = getDirectory('./Tender', $ignore);
?
pre
?
print_r($dirTree);
?
/pre

?php
getdirectory('./Tender');
//or
//get_dir_iterative(/*etc.*/);
?






Here is an example of what I'm getting out from the $dirTree array:

Array
(
[./Tender] = Array
(
[0] = 9216_100_REV_V1.0_bound.dwg
)


[./Tender/Tender Docs] = Array
(
[0] = BAA Works Terms v1.1 (22.05.08).pdf
[1] = Contents of Volumes 1 and 2.pdf
[2] = Cover Letter and Instructions.doc

[3] = Form of Tender.doc
)

[./Tender/Tender Docs/Health and Safety Questionnaire] = Array
(
[0] = NT Baggage Tender Questionaire rev2.xls
)


[./Tender/Tender Docs/NTB BH Lighting] = Array
(
[0] = 3J-B-1 PIR.xls
[1] = 3J-B-2B PIR.xls
[2] = 3J-B-2R PIR.xls
[3] = 3J-B-3R PIR.xls

[4] = 3J-D PIR.xls
[5] = 4G-G PIR.xls
[6] = 4J-B-1B PIR.xls
[7] = 4J-B-1R PIR.xls
[8] = 4J-B-2B PIR.xls
[9] = 4J-B-2R PIR.xls

[10] = 4J-B-4 PIR.xls
[11] = 5G-G PIR.xls
)

I'm having problems getting my head round how to get access the array
data so that I can format it how I want, eg:

Folder   Filename
Tender   9216_100_REV_V1.0_bound.dwg
Tender/Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
Tender/Tender Docs   Contents of Volumes 1 and 2.pdf

etc.

I'm trying to do this at work (php is a hobby and this is the first
time I've tried to use it in my electrical engineering job) in notepad
without any code highlighting, etc. and tearing my hair out to try and
avoid going through the CD manually!

Could anybody please help or let me know which function I need to read
up on? I've tried countless searches on array formatting, etc and not
getting anywhere.

Thanks in advance,

Tom



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Directory Listing

2009-08-25 Thread Ashley Sheridan
On Tue, 2009-08-25 at 12:06 +0200, Ralph Deffke wrote:
 I would say
 foreach( $dirTree as $key = $value ){
 echo $key .br;
 foreach( $value as $v){
 echo $v .br;
 }
 }
 
 something like that
 
 ralph_def...@yahoo.de
 Tom Chubb tomch...@gmail.com wrote in message
 news:4577934f0908250241i195dc691x3f8c552e72791...@mail.gmail.com...
 Hi gang,
 I'm trying to create a script to read the files in a folder (approx
 2000) and get the filename, path and last modified date in a tabulated
 format to copy into excel. (We have been issued a CD and need to get
 all files documented and assigned to an owner.)
 
 I've tried loads of different scripts but can't get them working with
 all the features.
 I think the best one to work with is this (although I'm having
 problems getting the date but don't worry about that at the moment)
 
 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function getDirectory($path = '.', $ignore = '') {
 $dirTree = array ();
 $dirTreeTemp = array ();
 $ignore[] = '.';
 $ignore[] = '..';
 
 $dh = @opendir($path);
 
 while (false !== ($file = readdir($dh))) {
 
 if (!in_array($file, $ignore)) {
 if (!is_dir($path/$file)) {
 
 $dirTree[$path][] = $file;
 
 } else {
 
 $dirTreeTemp = getDirectory($path/$file, $ignore);
 if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp);
 }
 }
 }
 closedir($dh);
 
 return $dirTree;
 }
 
 $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
 '.ftpquota');
 
 $dirTree = getDirectory('./Tender', $ignore);
 ?
 pre
 ?
 print_r($dirTree);
 ?
 /pre
 
 ?php
 getdirectory('./Tender');
 //or
 //get_dir_iterative(/*etc.*/);
 ?
 
 
 
 
 
 
 Here is an example of what I'm getting out from the $dirTree array:
 
 Array
 (
 [./Tender] = Array
 (
 [0] = 9216_100_REV_V1.0_bound.dwg
 )
 
 
 [./Tender/Tender Docs] = Array
 (
 [0] = BAA Works Terms v1.1 (22.05.08).pdf
 [1] = Contents of Volumes 1 and 2.pdf
 [2] = Cover Letter and Instructions.doc
 
 [3] = Form of Tender.doc
 )
 
 [./Tender/Tender Docs/Health and Safety Questionnaire] = Array
 (
 [0] = NT Baggage Tender Questionaire rev2.xls
 )
 
 
 [./Tender/Tender Docs/NTB BH Lighting] = Array
 (
 [0] = 3J-B-1 PIR.xls
 [1] = 3J-B-2B PIR.xls
 [2] = 3J-B-2R PIR.xls
 [3] = 3J-B-3R PIR.xls
 
 [4] = 3J-D PIR.xls
 [5] = 4G-G PIR.xls
 [6] = 4J-B-1B PIR.xls
 [7] = 4J-B-1R PIR.xls
 [8] = 4J-B-2B PIR.xls
 [9] = 4J-B-2R PIR.xls
 
 [10] = 4J-B-4 PIR.xls
 [11] = 5G-G PIR.xls
 )
 
 I'm having problems getting my head round how to get access the array
 data so that I can format it how I want, eg:
 
 Folder   Filename
 Tender   9216_100_REV_V1.0_bound.dwg
 Tender/Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
 Tender/Tender Docs   Contents of Volumes 1 and 2.pdf
 
 etc.
 
 I'm trying to do this at work (php is a hobby and this is the first
 time I've tried to use it in my electrical engineering job) in notepad
 without any code highlighting, etc. and tearing my hair out to try and
 avoid going through the CD manually!
 
 Could anybody please help or let me know which function I need to read
 up on? I've tried countless searches on array formatting, etc and not
 getting anywhere.
 
 Thanks in advance,
 
 Tom
 
 
 
Funnily enough, I've had to dust off an old function I wrote for this
sort of thing this very morning:

function dirTree($dir)
{
$dirs = Array();
if($dh = opendir($dir))
{
$dirCount = 0;
while(false !== ($file = readdir($dh)))
{
// ignore the pseudo . and .. directories
if( $file == '.' || $file == '..')
{
continue;
}
$path = str_replace('//', '/', $dir/$file);
if(is_dir($path))
{
$dirs[$path] = dirTree($path);
$dirCount ++;
}
if(is_file($path) )
{
// process this file

}
}
if($dirCount  0)
{
return $dirs;
}
else
{
return false;
}
}
else
{
return false;
}
}

$dir = /home/user/Documents/;
$tree = dirTree($dir);

The array $tree is a multidimensional array which should make sense to
look at if you do a print_r() on it!

The code looks a bit messy, and could be improved probably a dozen ways,
but it does work, and is 

Re: [PHP] Re: Directory Listing

2009-08-25 Thread Tom Chubb
2009/8/25 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Tue, 2009-08-25 at 12:06 +0200, Ralph Deffke wrote:
 I would say
 foreach( $dirTree as $key = $value ){
     echo $key .br;
     foreach( $value as $v){
         echo $v .br;
     }
 }

 something like that

 ralph_def...@yahoo.de
 Tom Chubb tomch...@gmail.com wrote in message
 news:4577934f0908250241i195dc691x3f8c552e72791...@mail.gmail.com...
 Hi gang,
 I'm trying to create a script to read the files in a folder (approx
 2000) and get the filename, path and last modified date in a tabulated
 format to copy into excel. (We have been issued a CD and need to get
 all files documented and assigned to an owner.)

 I've tried loads of different scripts but can't get them working with
 all the features.
 I think the best one to work with is this (although I'm having
 problems getting the date but don't worry about that at the moment)

 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function getDirectory($path = '.', $ignore = '') {
 $dirTree = array ();
 $dirTreeTemp = array ();
 $ignore[] = '.';
 $ignore[] = '..';

 $dh = @opendir($path);

 while (false !== ($file = readdir($dh))) {

 if (!in_array($file, $ignore)) {
 if (!is_dir($path/$file)) {

 $dirTree[$path][] = $file;

 } else {

 $dirTreeTemp = getDirectory($path/$file, $ignore);
 if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp);
 }
 }
 }
 closedir($dh);

 return $dirTree;
 }

 $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
 '.ftpquota');

 $dirTree = getDirectory('./Tender', $ignore);
 ?
 pre
 ?
 print_r($dirTree);
 ?
 /pre

 ?php
 getdirectory('./Tender');
 //or
 //get_dir_iterative(/*etc.*/);
 ?






 Here is an example of what I'm getting out from the $dirTree array:

     Array
 (
     [./Tender] = Array
         (
             [0] = 9216_100_REV_V1.0_bound.dwg
         )


     [./Tender/Tender Docs] = Array
         (
             [0] = BAA Works Terms v1.1 (22.05.08).pdf
             [1] = Contents of Volumes 1 and 2.pdf
             [2] = Cover Letter and Instructions.doc

             [3] = Form of Tender.doc
         )

     [./Tender/Tender Docs/Health and Safety Questionnaire] = Array
         (
             [0] = NT Baggage Tender Questionaire rev2.xls
         )


     [./Tender/Tender Docs/NTB BH Lighting] = Array
         (
             [0] = 3J-B-1 PIR.xls
             [1] = 3J-B-2B PIR.xls
             [2] = 3J-B-2R PIR.xls
             [3] = 3J-B-3R PIR.xls

             [4] = 3J-D PIR.xls
             [5] = 4G-G PIR.xls
             [6] = 4J-B-1B PIR.xls
             [7] = 4J-B-1R PIR.xls
             [8] = 4J-B-2B PIR.xls
             [9] = 4J-B-2R PIR.xls

             [10] = 4J-B-4 PIR.xls
             [11] = 5G-G PIR.xls
         )

 I'm having problems getting my head round how to get access the array
 data so that I can format it how I want, eg:

 Folder   Filename
 Tender   9216_100_REV_V1.0_bound.dwg
 Tender/Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
 Tender/Tender Docs   Contents of Volumes 1 and 2.pdf

 etc.

 I'm trying to do this at work (php is a hobby and this is the first
 time I've tried to use it in my electrical engineering job) in notepad
 without any code highlighting, etc. and tearing my hair out to try and
 avoid going through the CD manually!

 Could anybody please help or let me know which function I need to read
 up on? I've tried countless searches on array formatting, etc and not
 getting anywhere.

 Thanks in advance,

 Tom



 Funnily enough, I've had to dust off an old function I wrote for this
 sort of thing this very morning:

 function dirTree($dir)
 {
        $dirs = Array();
        if($dh = opendir($dir))
        {
                $dirCount = 0;
                while(false !== ($file = readdir($dh)))
                {
                        // ignore the pseudo . and .. directories
                        if( $file == '.' || $file == '..')
                        {
                                continue;
                        }
                        $path = str_replace('//', '/', $dir/$file);
                        if(is_dir($path))
                        {
                                $dirs[$path] = dirTree($path);
                                $dirCount ++;
                        }
                        if(is_file($path) )
                        {
                                // process this file

                        }
                }
                if($dirCount  0)
                {
                        return $dirs;
                }
                else
                {
                        return false;
                }
        }
        else
        {
                return false;
        }
 }

 $dir = /home/user/Documents/;
 $tree = dirTree($dir);

 The array $tree is a multidimensional array which should make sense to
 look at if you do a print_r() on it!

 The code looks a bit messy, and could be improved probably a dozen ways,
 

Re: [PHP] Re: Directory Listing

2009-08-25 Thread Tom Chubb
2009/8/25 Ralph Deffke ralph_def...@yahoo.de:
 I would say
 foreach( $dirTree as $key = $value ){
    echo $key .br;
    foreach( $value as $v){
        echo $v .br;
    }
 }

 something like that

 ralph_def...@yahoo.de
 Tom Chubb tomch...@gmail.com wrote in message
 news:4577934f0908250241i195dc691x3f8c552e72791...@mail.gmail.com...
 Hi gang,
 I'm trying to create a script to read the files in a folder (approx
 2000) and get the filename, path and last modified date in a tabulated
 format to copy into excel. (We have been issued a CD and need to get
 all files documented and assigned to an owner.)

 I've tried loads of different scripts but can't get them working with
 all the features.
 I think the best one to work with is this (although I'm having
 problems getting the date but don't worry about that at the moment)

 ?
 error_reporting(E_ALL);
 ini_set('display_errors', true);
 function getDirectory($path = '.', $ignore = '') {
 $dirTree = array ();
 $dirTreeTemp = array ();
 $ignore[] = '.';
 $ignore[] = '..';

 $dh = @opendir($path);

 while (false !== ($file = readdir($dh))) {

 if (!in_array($file, $ignore)) {
 if (!is_dir($path/$file)) {

 $dirTree[$path][] = $file;

 } else {

 $dirTreeTemp = getDirectory($path/$file, $ignore);
 if (is_array($dirTreeTemp))$dirTree =
 array_merge($dirTree, $dirTreeTemp);
 }
 }
 }
 closedir($dh);

 return $dirTree;
 }

 $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
 '.ftpquota');

 $dirTree = getDirectory('./Tender', $ignore);
 ?
 pre
 ?
 print_r($dirTree);
 ?
 /pre

 ?php
 getdirectory('./Tender');
 //or
 //get_dir_iterative(/*etc.*/);
 ?






 Here is an example of what I'm getting out from the $dirTree array:

    Array
 (
    [./Tender] = Array
        (
            [0] = 9216_100_REV_V1.0_bound.dwg
        )


    [./Tender/Tender Docs] = Array
        (
            [0] = BAA Works Terms v1.1 (22.05.08).pdf
            [1] = Contents of Volumes 1 and 2.pdf
            [2] = Cover Letter and Instructions.doc

            [3] = Form of Tender.doc
        )

    [./Tender/Tender Docs/Health and Safety Questionnaire] = Array
        (
            [0] = NT Baggage Tender Questionaire rev2.xls
        )


    [./Tender/Tender Docs/NTB BH Lighting] = Array
        (
            [0] = 3J-B-1 PIR.xls
            [1] = 3J-B-2B PIR.xls
            [2] = 3J-B-2R PIR.xls
            [3] = 3J-B-3R PIR.xls

            [4] = 3J-D PIR.xls
            [5] = 4G-G PIR.xls
            [6] = 4J-B-1B PIR.xls
            [7] = 4J-B-1R PIR.xls
            [8] = 4J-B-2B PIR.xls
            [9] = 4J-B-2R PIR.xls

            [10] = 4J-B-4 PIR.xls
            [11] = 5G-G PIR.xls
        )

 I'm having problems getting my head round how to get access the array
 data so that I can format it how I want, eg:

 Folder   Filename
 Tender   9216_100_REV_V1.0_bound.dwg
 Tender/Tender Docs   BAA Works Terms v1.1 (22.05.08).pdf
 Tender/Tender Docs   Contents of Volumes 1 and 2.pdf

 etc.

 I'm trying to do this at work (php is a hobby and this is the first
 time I've tried to use it in my electrical engineering job) in notepad
 without any code highlighting, etc. and tearing my hair out to try and
 avoid going through the CD manually!

 Could anybody please help or let me know which function I need to read
 up on? I've tried countless searches on array formatting, etc and not
 getting anywhere.

 Thanks in advance,

 Tom



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



Ended up tidying it up and using Ralph's idea and now working nicely.
(Need to 'view source' to see it properly as I was having issues
copying into excel but this is fine for what I'm trying to do.)

Now I'm having problems getting the file date.
I'm using: $modDate[$file][] = date (d m Y, filemtime($file));
and trying to merge it into the array but I'm missing something. Any
ideas?
Refer to lines 5, 14, 17,


New code:

?
function getDirectory($path = '.', $ignore = '') {
$dirTree = array ();
$dirTreeTemp = array ();
$modDate = array ();
$ignore[] = '.';
$ignore[] = '..';
$dh = @opendir($path);

while (false !== ($file = readdir($dh))) {
if (!in_array($file, $ignore)) {
if (!is_dir($path/$file)) {
$dirTree[$path][] = $file;
$modDate[$file][] = date (d m Y,
filemtime($file));
} else {
$dirTreeTemp = getDirectory($path/$file, $ignore);
if (is_array($dirTreeTemp))$dirTree =
array_merge($dirTree, $dirTreeTemp, $modDate);
//if (is_array($dirTreeTemp))$dirTree =
array_merge($dirTree, $dirTreeTemp);
}
}
}
closedir($dh);
return $dirTree;
}

$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');
$dirTree = getDirectory('./Tender', $ignore);
getdirectory('./Tender');

echo Gatwick Tender Documents\n;

foreach( $dirTree as $key = $folder ){
   //echo $key . \n; //Don't 

Re: [PHP] Re: Directory Listing

2009-08-25 Thread Tom Chubb
I've been playing about more and now I have the following code:

?
error_reporting(E_ALL);
ini_set('display_errors', true);

function getDirectory($path = '.', $ignore = '') {
$dirTree = array ();
$dirTreeTemp = array ();
$fileDate = array ();
$ignore[] = '.';
$ignore[] = '..';
$dh = @opendir($path);
while (false !== ($file = readdir($dh))) {
if (!in_array($file, $ignore)) {
if (!is_dir($path/$file)) {
$dirTree[$path][] = $file;
$fileDate[$file][] = date (d/m/Y,
filemtime($path/$file));
} else {
$dirTreeTemp = getDirectory($path/$file, $ignore);
if (is_array($dirTreeTemp))$dirTree =
array_merge($dirTree, $dirTreeTemp, $fileDate);
}
}
}
closedir($dh);
return $dirTree;
}

$ignore = array('.htaccess', 'Thumbs.db', 'index.php');
$dirTree = getDirectory('.', $ignore);
getdirectory('.');

echo Gatwick Tender Documents\n;

foreach( $dirTree as $key = $folder ){
   echo \n; //Don't need folders as they're shown with the files
   foreach( $folder as $file){
   echo str_replace(./, , $key) . \t . $file . \t\n; //Pad
out with a tab for easy import into excel

   }
}
print_r($dirTree); //Just using this for debugging
?


The output is fine for the paths and filenames but I still can't get
the dates showing. It's getting the correct date for some but not all.
I did something else earlier and found that all the dates were
01/01/1970 but at least there was a date for every file but can't
remember how I go there!


Here is a sample output result:

Gatwick Tender Documents

.   9216_100_REV_V1.0_bound.dwg 

Tender Docs BAA Works Terms v1.1 (22.05.08).pdf 
Tender Docs Contents of Volumes 1 and 2.pdf 
Tender Docs Cover Letter and Instructions.doc   
Tender Docs Form of Tender.doc  

Tender Docs/Health and Safety Questionnaire NT Baggage Tender
Questionaire rev2.xls

BAA Works Terms v1.1 (22.05.08).pdf 29/07/2009  

Contents of Volumes 1 and 2.pdf 29/07/2009  

Cover Letter and Instructions.doc   29/07/2009  

Form of Tender.doc  29/07/2009  

Tender Docs/NTB BH Lighting 3J-B-1 PIR.xls  
Tender Docs/NTB BH Lighting 3J-B-2B PIR.xls 
Tender Docs/NTB BH Lighting 3J-B-2R PIR.xls 
Tender Docs/NTB BH Lighting 3J-B-3R PIR.xls 
Tender Docs/NTB BH Lighting 3J-D PIR.xls
Tender Docs/NTB BH Lighting 4G-G PIR.xls
Tender Docs/NTB BH Lighting 4J-B-1B PIR.xls 
Tender Docs/NTB BH Lighting 4J-B-1R PIR.xls 
Tender Docs/NTB BH Lighting 4J-B-2B PIR.xls 
Tender Docs/NTB BH Lighting 4J-B-2R PIR.xls 
Tender Docs/NTB BH Lighting 4J-B-4 PIR.xls  
Tender Docs/NTB BH Lighting 5G-G PIR.xls


Can anyone shed any light on it?
I'm about to admit defeat!

Thanks in advance and I'm not being lazy - I really am trying!!! :(

Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Directory Listing and File Reading errors

2001-09-05 Thread Richard Lynch

 I'm recursivley reading and editing every .htm and .html file in a 500
page
 website and upgrading it to contain linked CSS, Javascript includes and
PHP
 includes. i can't use a pre_pend file as there's more than one website on
 the server, and the changes are embedded in the document rather than just
 the header/footer. the script works fine and all, trouble is that PHP
 doesn't.

 Sometimes the script will run fine, other times PHP will decide to read
the
 same file 10-20 times and then do the same for everyfile in certain
 directories. it's really annoying as some changes will be made over and
over
 and over, also with 500 files being read 5-10 times each, the page times
out
 after about 5000 reads...

 is this a PHP bug? or an Microsoft bug? or something else...

 i'm running PHP verson 4.0.4pl1 off a 2000 server and IIS

First, are you 100% sure you are correctly recursing through directories?
Show us the source.

Second: It *may* be possible that modifying the files in the midst of
opendir/readdir is shuffling enough things around on the hard drive that you
are confusing the OS.  (It is Windows, after all)

What you might try would be to use opendir/readdir to create a monster array
of every path you want to alter.  Then, walk through that array and do the
alterations.

You can even dump out the array first and check it by hand to be sure it's
want you think it should be, and then turn on the code in a second run to do
the alteration.

If all else fails -- If you're able to add this stuff into the file, you can
probably detect if it's already been added, and skip a file you already
edited...

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]