Re: [PHP] Re: Directory Listing
use realpath is better that i think 2009/8/26 Steve : > Ashley Sheridan wrote: >> >> On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote: >> >>> >>> 2009/8/26 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.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! >>> >>> >> 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)); >>>
Re: [PHP] Re: Directory Listing
Ashley Sheridan wrote: On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote: 2009/8/26 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: $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! The output I'm getting is: /9216_100_REV_V1.0_bound.dwg05/08/2009 /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf29/07/2009 /Tender Docs/Contents of Volumes 1 and 2.pdf29/07/2009 /Tender Docs/Cover Letter and Instructions.doc 29/07/2009 /Tender Docs/Form of Tender.doc 29/07/2009 /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender Questionaire rev2.xls 29/07/2009 /Tender Docs/Health and Safety Questionnaire14/08/2009 /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-D PIR.xls 13/05/2009 All I need to do now is get a tab between the filename & the path I'm thinking I need to explode on the "/" and somehow match the last value but stumped at the moment! Tom You could do a substr on $file: $filename = substr($file, strrpos('/')+1); $directory = substr($file, 0, strlen($file) - strrpos('/')); I've not tested that, so you might need to adjust slightly a character position here or there. Thanks, Ash http://www.ashleysheridan.co.u It might make more sense to use the basename and dirname functions for that. Though you will probably still run into the misplaced tabs if your paths don't have trailing slashes. At least it's cleaner. $filename = basename($file); $directory = dirname($file); http://www.php.net/manual/function.basename.php http://www.php.net/manual/function.dirname.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Directory Listing
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
On Wed, Aug 26, 2009 at 9:45 AM, hack988 hack988 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
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/8/26 hack988 hack988 : > your means "Health and Safety Questionnaire"is directory? > so you want it display like this > full dir path <> filename<>date > 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
your means "Health and Safety Questionnaire"is directory? so you want it display like this full dir path <> filename<>date -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Directory Listing
2009/8/26 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 > > > > 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/8/26 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. > To clarify - this is what I was getting: /<<>>9216_100_REV_V1.0_bound.dwg<<>>05/08/2009 /Tender Docs/<<>>BAA Works Terms v1.1 (22.05.08).pdf<<>>29/07/2009 /Tender Docs/<<>>Health 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
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
"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/8/26 Ashley Sheridan : > On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote: >> 2009/8/26 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.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! >> >> > 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; >>
Re: [PHP] Re: Directory Listing
On Wed, 2009-08-26 at 09:50 +0100, Tom Chubb wrote: > 2009/8/26 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 > > > > > > > > > > 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! > > 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 { >
Re: [PHP] Re: Directory Listing
2009/8/26 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.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! The output I'm getting is: /9216_100_REV_V1.0_bound.dwg05/08/2009 /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf29/07/2009 /Tender Docs/Contents of Volumes 1 and 2.pdf29/07/2009 /Tender Docs/Cover Letter and Instructions.doc 29/07/2009 /Tender Docs/Form of Tender.doc 29/07/2009 /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender Questionaire rev2.xls 29/07/2009 /Tender Docs/Health and Safety Questionnaire14/08/2009 /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls13/05/2009 /Tender Docs/NTB BH Lighting/3J-D PIR.xls 13/05/2009 All I need to do now is get a tab between the filename & the path I'm thinking I need to explode on the "/" and somehow match the last value but stumped at the moment! Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Directory Listing
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
I've been playing about more and now I have the following code: $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
Re: [PHP] Re: Directory Listing
2009/8/25 Ralph Deffke : > I would say > foreach( $dirTree as $key => $value ){ > echo $key .""; > foreach( $value as $v){ > echo $v ."; > } > } > > something like that > > ralph_def...@yahoo.de > "Tom Chubb" 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); > ?> > > print_r($dirTree); > ?> > > > 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: $folder ){ //echo $key . "\n"; //Don't need folders as they're shown with the files foreach( $folder as $file){ echo str_replace("./Tender", "", $key) . "/\t" . $file . "\n"; } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Directory Listing
2009/8/25 Ashley Sheridan : > On Tue, 2009-08-25 at 12:06 +0200, Ralph Deffke wrote: >> I would say >> foreach( $dirTree as $key => $value ){ >> echo $key .""; >> foreach( $value as $v){ >> echo $v ."; >> } >> } >> >> something like that >> >> ralph_def...@yahoo.de >> "Tom Chubb" 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); >> ?> >> >> > print_r($dirTree); >> ?> >> >> >> > 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; > } > } >
Re: [PHP] Re: Directory Listing
On Tue, 2009-08-25 at 12:06 +0200, Ralph Deffke wrote: > I would say > foreach( $dirTree as $key => $value ){ > echo $key .""; > foreach( $value as $v){ > echo $v ."; > } > } > > something like that > > ralph_def...@yahoo.de > "Tom Chubb" 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); > ?> > > print_r($dirTree); > ?> > > > 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 se
[PHP] Re: Directory Listing
I would say foreach( $dirTree as $key => $value ){ echo $key .""; foreach( $value as $v){ echo $v ."; } } something like that ralph_def...@yahoo.de "Tom Chubb" 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) 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
[PHP] Re: Directory Listing and File Reading errors
> 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]
[PHP] RE: Directory Listing with PHP
don't know what apache does but this will give you everything below the pathn you pass in. function sitemap($ddPath) { $dhandle = opendir($ddPath); echo(""); while ($ddFile = readdir($dhandle)) { if ($ddFile == "." or $ddFile == "..") continue; // trap . and .. echo("".$ddFile . ""); if (is_dir($ddPath . $ddFile)) sitemap($ddPath . $ddFile . "/"); }; closedir($dhandle); echo(""); }; Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -Original Message- > From: Chris Aitken [mailto:[EMAIL PROTECTED]] > Sent: 01 February 2001 05:05 > To: PHP User Group > Subject: Directory Listing with PHP > > > > > (Damn I hate it when I forget to change the subject) > > > Does anyone have, or know of a script which simulates what > Apache gives out > when it shows the entire contents of a directory ? > > I find it very handy to use the directory listing of say graphics > directories and the like, but I dont want others looking into them. > > What I thought would be a good system is to have an index.php > file which > asks for a password. If the password is accepted, it shoots > them off to a > php script which displays the contents of the DIR just as > apache would. > > This way I can bar viewing of the directories contents, only > viewable to > the owners of the password. > > > Ive seen a couple of scripts which claim to show the > directory listing, but > none of them seem to work any good with a decent layout and > amount of file > info. So im looking for a script which can display the > listing properly. > Does one exist, or am I just relieving myself into the wind ? > > > Thanks > > Chris > > -- >Chris Aitken - Webmaster/Database Designer - IDEAL Internet > email: [EMAIL PROTECTED] phone: +61 2 4628 fax: +61 2 > 4628 8890 > > >Unix -- because a computer's a terrible thing to waste! > > -- 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]