Directory Listing
am 25.08.2009 11:41:59 von Tom Chubb
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 =3D '.', $ignore =3D '') {
=A0 $dirTree =3D array ();
=A0 $dirTreeTemp =3D array ();
=A0 $ignore[] =3D '.';
=A0 $ignore[] =3D '..';
=A0 $dh =3D @opendir($path);
=A0 while (false !== ($file =3D readdir($dh))) {
=A0 if (!in_array($file, $ignore)) {
=A0 if (!is_dir("$path/$file")) {
=A0 $dirTree["$path"][] =3D $file=
;
=A0 } else {
=A0 $dirTreeTemp =3D getDirectory=
("$path/$file", $ignore);
=A0 if (is_array($dirTreeTemp))$d=
irTree =3D
array_merge($dirTree, $dirTreeTemp);
=A0 }
=A0 }
=A0 }
=A0 closedir($dh);
=A0 return $dirTree;
}
$ignore =3D array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquot=
a');
$dirTree =3D getDirectory('./Tender', $ignore);
?>
=A0
=A0 print_r($dirTree);
=A0 ?>
getdirectory('./Tender');
//or
//get_dir_iterative(/*etc.*/);
?>
Here is an example of what I'm getting out from the $dirTree array:
Array
(
[./Tender] =3D> Array
(
[0] =3D> 9216_100_REV_V1.0_bound.dwg
)
[./Tender/Tender Docs] =3D> Array
(
[0] =3D> BAA Works Terms v1.1 (22.05.08).pdf
[1] =3D> Contents of Volumes 1 and 2.pdf
[2] =3D> Cover Letter and Instructions.doc
[3] =3D> Form of Tender.doc
)
[./Tender/Tender Docs/Health and Safety Questionnaire] =3D> Array
(
[0] =3D> NT Baggage Tender Questionaire rev2.xls
)
[./Tender/Tender Docs/NTB BH Lighting] =3D> Array
(
[0] =3D> 3J-B-1 PIR.xls
[1] =3D> 3J-B-2B PIR.xls
[2] =3D> 3J-B-2R PIR.xls
[3] =3D> 3J-B-3R PIR.xls
[4] =3D> 3J-D PIR.xls
[5] =3D> 4G-G PIR.xls
[6] =3D> 4J-B-1B PIR.xls
[7] =3D> 4J-B-1R PIR.xls
[8] =3D> 4J-B-2B PIR.xls
[9] =3D> 4J-B-2R PIR.xls
[10] =3D> 4J-B-4 PIR.xls
[11] =3D> 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: Directory Listing
am 25.08.2009 12:06:20 von Ralph Deffke
I would say
foreach( $dirTree as $key => $value ){
echo $key ."
";
foreach( $value as $v){
echo $v ."
;
}
}
something like that
ralph_deffke@yahoo.de
"Tom Chubb" wrote in message
news:4577934f0908250241i195dc691x3f8c552e72791f4e@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
Re: Re: Directory Listing
am 25.08.2009 12:44:49 von 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_deffke@yahoo.de
> "Tom Chubb" wrote in message
> news:4577934f0908250241i195dc691x3f8c552e72791f4e@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 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 very easy to mess around with.
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: Re: Directory Listing
am 25.08.2009 12:53:20 von Tom Chubb
2009/8/25 Ashley Sheridan :
> On Tue, 2009-08-25 at 12:06 +0200, Ralph Deffke wrote:
>> I would say
>> foreach( $dirTree as $key =3D> $value ){
>> =A0 =A0 echo $key ."
";
>> =A0 =A0 foreach( $value as $v){
>> =A0 =A0 =A0 =A0 echo $v ."
;
>> =A0 =A0 }
>> }
>>
>> something like that
>>
>> ralph_deffke@yahoo.de
>> "Tom Chubb" wrote in message
>> news:4577934f0908250241i195dc691x3f8c552e72791f4e@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 =3D '.', $ignore =3D '') {
>> $dirTree =3D array ();
>> $dirTreeTemp =3D array ();
>> $ignore[] =3D '.';
>> $ignore[] =3D '..';
>>
>> $dh =3D @opendir($path);
>>
>> while (false !== ($file =3D readdir($dh))) {
>>
>> if (!in_array($file, $ignore)) {
>> if (!is_dir("$path/$file")) {
>>
>> $dirTree["$path"][] =3D $file;
>>
>> } else {
>>
>> $dirTreeTemp =3D getDirectory("$path/$file", $ignore);
>> if (is_array($dirTreeTemp))$dirTree =3D
>> array_merge($dirTree, $dirTreeTemp);
>> }
>> }
>> }
>> closedir($dh);
>>
>> return $dirTree;
>> }
>>
>> $ignore =3D array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
>> '.ftpquota');
>>
>> $dirTree =3D 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:
>>
>> =A0 =A0 Array
>> (
>> =A0 =A0 [./Tender] =3D> Array
>> =A0 =A0 =A0 =A0 (
>> =A0 =A0 =A0 =A0 =A0 =A0 [0] =3D> 9216_100_REV_V1.0_bound.dwg
>> =A0 =A0 =A0 =A0 )
>>
>>
>> =A0 =A0 [./Tender/Tender Docs] =3D> Array
>> =A0 =A0 =A0 =A0 (
>> =A0 =A0 =A0 =A0 =A0 =A0 [0] =3D> BAA Works Terms v1.1 (22.05.08).pdf
>> =A0 =A0 =A0 =A0 =A0 =A0 [1] =3D> Contents of Volumes 1 and 2.pdf
>> =A0 =A0 =A0 =A0 =A0 =A0 [2] =3D> Cover Letter and Instructions.doc
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 [3] =3D> Form of Tender.doc
>> =A0 =A0 =A0 =A0 )
>>
>> =A0 =A0 [./Tender/Tender Docs/Health and Safety Questionnaire] =3D> Arra=
y
>> =A0 =A0 =A0 =A0 (
>> =A0 =A0 =A0 =A0 =A0 =A0 [0] =3D> NT Baggage Tender Questionaire rev2.xls
>> =A0 =A0 =A0 =A0 )
>>
>>
>> =A0 =A0 [./Tender/Tender Docs/NTB BH Lighting] =3D> Array
>> =A0 =A0 =A0 =A0 (
>> =A0 =A0 =A0 =A0 =A0 =A0 [0] =3D> 3J-B-1 PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [1] =3D> 3J-B-2B PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [2] =3D> 3J-B-2R PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [3] =3D> 3J-B-3R PIR.xls
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 [4] =3D> 3J-D PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [5] =3D> 4G-G PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [6] =3D> 4J-B-1B PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [7] =3D> 4J-B-1R PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [8] =3D> 4J-B-2B PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [9] =3D> 4J-B-2R PIR.xls
>>
>> =A0 =A0 =A0 =A0 =A0 =A0 [10] =3D> 4J-B-4 PIR.xls
>> =A0 =A0 =A0 =A0 =A0 =A0 [11] =3D> 5G-G PIR.xls
>> =A0 =A0 =A0 =A0 )
>>
>> 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 =A0 Filename
>> Tender =A0 9216_100_REV_V1.0_bound.dwg
>> Tender/Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
>> Tender/Tender Docs =A0 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)
> {
> =A0 =A0 =A0 =A0$dirs =3D Array();
> =A0 =A0 =A0 =A0if($dh =3D opendir($dir))
> =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirCount =3D 0;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0while(false !== ($file =3D readdir($dh=
)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// ignore the pseudo . and=
.. directories
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if( $file == '.' || $f=
ile == '..')
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$path =3D str_replace('//'=
, '/', "$dir/$file");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(is_dir($path))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirs[$pat=
h] =3D dirTree($path);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirCount =
++;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if(is_file($path) )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// process=
this file
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if($dirCount > 0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return $dirs;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return false;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return false;
> =A0 =A0 =A0 =A0}
> }
>
> $dir =3D "/home/user/Documents/";
> $tree =3D 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 very easy to mess around with.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Thanks Ash,
I've never really worked with arrays and until now I never understood
what a multi-dimensional array was!
I'll try and mess around with it.
Thanks to Ralph also.
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 25.08.2009 13:41:18 von Tom Chubb
2009/8/25 Ralph Deffke :
> I would say
> foreach( $dirTree as $key =3D> $value ){
> =A0 =A0echo $key ."
";
> =A0 =A0foreach( $value as $v){
> =A0 =A0 =A0 =A0echo $v ."
;
> =A0 =A0}
> }
>
> something like that
>
> ralph_deffke@yahoo.de
> "Tom Chubb" wrote in message
> news:4577934f0908250241i195dc691x3f8c552e72791f4e@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 =3D '.', $ignore =3D '') {
> $dirTree =3D array ();
> $dirTreeTemp =3D array ();
> $ignore[] =3D '.';
> $ignore[] =3D '..';
>
> $dh =3D @opendir($path);
>
> while (false !== ($file =3D readdir($dh))) {
>
> if (!in_array($file, $ignore)) {
> if (!is_dir("$path/$file")) {
>
> $dirTree["$path"][] =3D $file;
>
> } else {
>
> $dirTreeTemp =3D getDirectory("$path/$file", $ignore);
> if (is_array($dirTreeTemp))$dirTree =3D
> array_merge($dirTree, $dirTreeTemp);
> }
> }
> }
> closedir($dh);
>
> return $dirTree;
> }
>
> $ignore =3D array('.htaccess', 'error_log', 'cgi-bin', 'php.ini',
> '.ftpquota');
>
> $dirTree =3D 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:
>
> =A0 =A0Array
> (
> =A0 =A0[./Tender] =3D> Array
> =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0[0] =3D> 9216_100_REV_V1.0_bound.dwg
> =A0 =A0 =A0 =A0)
>
>
> =A0 =A0[./Tender/Tender Docs] =3D> Array
> =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0[0] =3D> BAA Works Terms v1.1 (22.05.08).pdf
> =A0 =A0 =A0 =A0 =A0 =A0[1] =3D> Contents of Volumes 1 and 2.pdf
> =A0 =A0 =A0 =A0 =A0 =A0[2] =3D> Cover Letter and Instructions.doc
>
> =A0 =A0 =A0 =A0 =A0 =A0[3] =3D> Form of Tender.doc
> =A0 =A0 =A0 =A0)
>
> =A0 =A0[./Tender/Tender Docs/Health and Safety Questionnaire] =3D> Array
> =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0[0] =3D> NT Baggage Tender Questionaire rev2.xls
> =A0 =A0 =A0 =A0)
>
>
> =A0 =A0[./Tender/Tender Docs/NTB BH Lighting] =3D> Array
> =A0 =A0 =A0 =A0(
> =A0 =A0 =A0 =A0 =A0 =A0[0] =3D> 3J-B-1 PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[1] =3D> 3J-B-2B PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[2] =3D> 3J-B-2R PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[3] =3D> 3J-B-3R PIR.xls
>
> =A0 =A0 =A0 =A0 =A0 =A0[4] =3D> 3J-D PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[5] =3D> 4G-G PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[6] =3D> 4J-B-1B PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[7] =3D> 4J-B-1R PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[8] =3D> 4J-B-2B PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[9] =3D> 4J-B-2R PIR.xls
>
> =A0 =A0 =A0 =A0 =A0 =A0[10] =3D> 4J-B-4 PIR.xls
> =A0 =A0 =A0 =A0 =A0 =A0[11] =3D> 5G-G PIR.xls
> =A0 =A0 =A0 =A0)
>
> 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 =A0 Filename
> Tender =A0 9216_100_REV_V1.0_bound.dwg
> Tender/Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
> Tender/Tender Docs =A0 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"][] =3D 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 =3D '.', $ignore =3D '') {
$dirTree =3D array ();
$dirTreeTemp =3D array ();
$modDate =3D array ();
$ignore[] =3D '.';
$ignore[] =3D '..';
$dh =3D @opendir($path);
while (false !== ($file =3D readdir($dh))) {
if (!in_array($file, $ignore)) {
if (!is_dir("$path/$file")) {
$dirTree["$path"][] =3D $file;
$modDate["$file"][] =3D date ("d m Y",
filemtime($file));
} else {
$dirTreeTemp =3D getDirectory("$path/$file", $ignore);
if (is_array($dirTreeTemp))$dirTree =3D
array_merge($dirTree, $dirTreeTemp, $modDate);
// if (is_array($dirTreeTemp))$dirTree =3D
array_merge($dirTree, $dirTreeTemp);
}
}
}
closedir($dh);
return $dirTree;
}
$ignore =3D array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquot=
a');
$dirTree =3D getDirectory('./Tender', $ignore);
getdirectory('./Tender');
echo "Gatwick Tender Documents\n";
foreach( $dirTree as $key =3D> $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: Re: Directory Listing
am 25.08.2009 18:08:25 von 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
Re: Re: Directory Listing
am 26.08.2009 09:59:30 von 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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 26.08.2009 10:50:07 von Tom Chubb
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 =3D '.', $ignore =3D '') {
>> =A0 =A0 $dirTree =3D array ();
>> =A0 =A0 $dirTreeTemp =3D array ();
>> =A0 =A0 $fileDate =3D array ();
>> =A0 =A0 $ignore[] =3D '.';
>> =A0 =A0 $ignore[] =3D '..';
>> =A0 =A0 $dh =3D @opendir($path);
>> =A0 =A0 while (false !== ($file =3D readdir($dh))) {
>> =A0 =A0 =A0 =A0 if (!in_array($file, $ignore)) {
>> =A0 =A0 =A0 =A0 =A0 =A0 if (!is_dir("$path/$file")) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $dirTree["$path"][] =3D $file;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $fileDate["$file"][] =3D date ("d/m/Y",
>> filemtime("$path/$file"));
>> =A0 =A0 =A0 =A0 =A0 =A0 } else {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $dirTreeTemp =3D getDirectory("$path/$fi=
le", $ignore);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_array($dirTreeTemp))$dirTree =3D
>> array_merge($dirTree, $dirTreeTemp, $fileDate);
>> =A0 =A0 =A0 =A0 =A0 =A0 }
>> =A0 =A0 =A0 =A0 }
>> =A0 =A0 }
>> =A0 =A0 closedir($dh);
>> =A0 =A0 return $dirTree;
>> }
>>
>> $ignore =3D array('.htaccess', 'Thumbs.db', 'index.php');
>> $dirTree =3D getDirectory('.', $ignore);
>> getdirectory('.');
>>
>> echo "Gatwick Tender Documents\n";
>>
>> foreach( $dirTree as $key =3D> $folder ){
>> =A0 =A0echo "\n"; //Don't need folders as they're shown with the files
>> =A0 =A0foreach( $folder as $file){
>> =A0 =A0 =A0 =A0echo str_replace("./", "", $key) . "\t" . $file . "\t\n";=
//Pad
>> out with a tab for easy import into excel
>>
>> =A0 =A0}
>> }
>> 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
>>
>> . =A0 =A0 9216_100_REV_V1.0_bound.dwg
>>
>> Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
>> Tender Docs =A0 Contents of Volumes 1 and 2.pdf
>> Tender Docs =A0 Cover Letter and Instructions.doc
>> Tender Docs =A0 Form of Tender.doc
>>
>> Tender Docs/Health and Safety Questionnaire =A0 NT Baggage Tender
>> Questionaire rev2.xls
>>
>> BAA Works Terms v1.1 (22.05.08).pdf =A0 29/07/2009
>>
>> Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 29/07/2009
>>
>> Cover Letter and Instructions.doc =A0 =A0 29/07/2009
>>
>> Form of Tender.doc =A0 =A029/07/2009
>>
>> Tender Docs/NTB BH Lighting =A0 3J-B-1 PIR.xls
>> Tender Docs/NTB BH Lighting =A0 3J-B-2B PIR.xls
>> Tender Docs/NTB BH Lighting =A0 3J-B-2R PIR.xls
>> Tender Docs/NTB BH Lighting =A0 3J-B-3R PIR.xls
>> Tender Docs/NTB BH Lighting =A0 3J-D PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4G-G PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4J-B-1B PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4J-B-1R PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4J-B-2B PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4J-B-2R PIR.xls
>> Tender Docs/NTB BH Lighting =A0 4J-B-4 PIR.xls
>> Tender Docs/NTB BH Lighting =A0 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 =3D array();
if ($handle =3D opendir($directory)) {
while (false !== ($file =3D readdir($handle))) {
if ($file !=3D"index.php" && $file !=3D "." && $file !=3D "..") {
if (is_dir($directory. "/" . $file)) {
//For Directories
if($recursive) {
$array_items =3D array_merge($array_items,
directoryToArray($directory. "/" . $file, $recursive));
}
$fullfile =3D $directory . "/" . $file;
$array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
} else {
//For Files
$fullfile =3D $directory . "/" . $file;
$array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
}
}
}
closedir($handle);
}
return $array_items;
}
$files =3D directoryToArray("./Tender", true);
//Output to browser
foreach ($files as $file) {
echo str_replace("./Tender", "", $file) . "\t" . " " . date ("d/m/Y",
filemtime($file)) . "\n";
}
//print_r($files);
?>
The output I'm getting is:
/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/Contents of Volumes 1 and 2.pdf 29/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 Questionnaire 14/08/2009
/Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009
/Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls 13/05/2009
/Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls 13/05/2009
/Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls 13/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: Re: Directory Listing
am 26.08.2009 10:53:30 von 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;
> $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";
> }
> //print_r($files);
> ?>
>
>
> The output I'm getting is:
> /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/Contents of Volumes 1 and 2.pdf 29/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 Questionnaire 14/08/2009
> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls 13/05/2009
> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls 13/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.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 26.08.2009 12:08:06 von Tom Chubb
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 =3D '.', $ignore =3D '') {
>> >> =A0 =A0 $dirTree =3D array ();
>> >> =A0 =A0 $dirTreeTemp =3D array ();
>> >> =A0 =A0 $fileDate =3D array ();
>> >> =A0 =A0 $ignore[] =3D '.';
>> >> =A0 =A0 $ignore[] =3D '..';
>> >> =A0 =A0 $dh =3D @opendir($path);
>> >> =A0 =A0 while (false !== ($file =3D readdir($dh))) {
>> >> =A0 =A0 =A0 =A0 if (!in_array($file, $ignore)) {
>> >> =A0 =A0 =A0 =A0 =A0 =A0 if (!is_dir("$path/$file")) {
>> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $dirTree["$path"][] =3D $file;
>> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $fileDate["$file"][] =3D date ("d/m/Y=
",
>> >> filemtime("$path/$file"));
>> >> =A0 =A0 =A0 =A0 =A0 =A0 } else {
>> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $dirTreeTemp =3D getDirectory("$path/=
$file", $ignore);
>> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_array($dirTreeTemp))$dirTree =
=3D
>> >> array_merge($dirTree, $dirTreeTemp, $fileDate);
>> >> =A0 =A0 =A0 =A0 =A0 =A0 }
>> >> =A0 =A0 =A0 =A0 }
>> >> =A0 =A0 }
>> >> =A0 =A0 closedir($dh);
>> >> =A0 =A0 return $dirTree;
>> >> }
>> >>
>> >> $ignore =3D array('.htaccess', 'Thumbs.db', 'index.php');
>> >> $dirTree =3D getDirectory('.', $ignore);
>> >> getdirectory('.');
>> >>
>> >> echo "Gatwick Tender Documents\n";
>> >>
>> >> foreach( $dirTree as $key =3D> $folder ){
>> >> =A0 =A0echo "\n"; //Don't need folders as they're shown with the file=
s
>> >> =A0 =A0foreach( $folder as $file){
>> >> =A0 =A0 =A0 =A0echo str_replace("./", "", $key) . "\t" . $file . "\t\=
n"; //Pad
>> >> out with a tab for easy import into excel
>> >>
>> >> =A0 =A0}
>> >> }
>> >> 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
>> >>
>> >> . =A0 =A0 9216_100_REV_V1.0_bound.dwg
>> >>
>> >> Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
>> >> Tender Docs =A0 Contents of Volumes 1 and 2.pdf
>> >> Tender Docs =A0 Cover Letter and Instructions.doc
>> >> Tender Docs =A0 Form of Tender.doc
>> >>
>> >> Tender Docs/Health and Safety Questionnaire =A0 NT Baggage Tender
>> >> Questionaire rev2.xls
>> >>
>> >> BAA Works Terms v1.1 (22.05.08).pdf =A0 29/07/2009
>> >>
>> >> Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 29/07/2009
>> >>
>> >> Cover Letter and Instructions.doc =A0 =A0 29/07/2009
>> >>
>> >> Form of Tender.doc =A0 =A029/07/2009
>> >>
>> >> Tender Docs/NTB BH Lighting =A0 3J-B-1 PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 3J-B-2B PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 3J-B-2R PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 3J-B-3R PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 3J-D PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4G-G PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4J-B-1B PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4J-B-1R PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4J-B-2B PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4J-B-2R PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 4J-B-4 PIR.xls
>> >> Tender Docs/NTB BH Lighting =A0 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 whe=
re
>> > the files were above 2GB each. When the files are that size, none of t=
he
>> > 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) {
>> =A0 =A0 =A0 $array_items =3D array();
>> =A0 =A0 =A0 if ($handle =3D opendir($directory)) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (false !== ($file =3D readdir($han=
dle))) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ($file !=3D"index.php" &&=
$file !=3D "." && $file !=3D "..") {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_dir($=
directory. "/" . $file)) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 //For Directories
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 if($recursive) {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 $array_items =3D array_merge($array_items,
>> directoryToArray($directory. "/" . $file, $recursive));
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 }
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 $fullfile =3D $directory . "/" . $file;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 $array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } else {
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 //For Files
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 $fullfile =3D $directory . "/" . $file;
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 $array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 closedir($handle);
>> =A0 =A0 =A0 }
>> =A0 =A0 =A0 return $array_items;
>> }
>>
>> $files =3D directoryToArray("./Tender", true);
>>
>>
>> //Output to browser
>> foreach ($files as $file) {
>> =A0 =A0 =A0 echo str_replace("./Tender", "", $file) . "\t" . " =A0 =A0 =
=A0" . date ("d/m/Y",
>> filemtime($file)) . "\n";
>> }
>> //print_r($files);
>> ?>
>>
>>
>> The output I'm getting is:
>> /9216_100_REV_V1.0_bound.dwg =A0 =A0 =A0 =A0 =A005/08/2009
>> /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf =A0 =A0 =A0 =A0 =A0 =A0=
=A029/07/2009
>> /Tender Docs/Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 =A0 =A029/07/20=
09
>> /Tender Docs/Cover Letter and Instructions.doc =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A029/07/2009
>> /Tender Docs/Form of Tender.doc =A0 =A0 =A0 =A0 =A0 =A0 =A0 29/07/2009
>> /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender
>> Questionaire rev2.xls =A0 =A0 =A0 =A0 29/07/2009
>> /Tender Docs/Health and Safety Questionnaire =A0 =A0 =A0 =A0 =A014/08/20=
09
>> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls =A0 =A0 =A0 =A0 =A0 13/05/20=
09
>> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls =A0 =A0 =A0 =A0 =A013/05/20=
09
>> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls =A0 =A0 =A0 =A0 =A013/05/20=
09
>> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls =A0 =A0 =A0 =A0 =A013/05/20=
09
>> /Tender Docs/NTB BH Lighting/3J-D PIR.xls =A0 =A0 =A0 =A0 =A0 =A0 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 =3D substr($file, strrpos('/')+1);
> $directory =3D 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.uk
>
>
>
>
Cheers Ash,
Slightly modified it to:
$filename =3D substr($file, strrpos($file, '/')+1);
$path =3D str_replace ($filename, "", $file);
Output is now showing:
/ 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/ Contents of Volumes 1 and 2.pdf 29/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 Questionnaire 14/08/2009
Only problem now is that the directories (last one in example above)
have a tab inserted in the middle of the path but I can live with
that!
Thanks for your help.
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 26.08.2009 12:21:17 von 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: Re: Directory Listing
am 26.08.2009 12:23:11 von 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: Re: Directory Listing
am 26.08.2009 12:27:40 von Tom Chubb
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<<
here>>>29/07/2009
/Tender Docs/<<>>Health and Safety Questionnaire 14/08/2009
--
Tom Chubb
tom@tomchubb.com | tomchubb@gmail.com
07912 202846
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 26.08.2009 12:28:46 von Tom Chubb
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
tom@tomchubb.com | tomchubb@gmail.com
07912 202846
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: Directory Listing
am 26.08.2009 14:22:28 von hack988 hack988
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: Re: Directory Listing
am 26.08.2009 14:30:35 von Tom Chubb
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: Re: Directory Listing
am 26.08.2009 15:45:11 von 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: Re: Directory Listing
am 26.08.2009 15:50:13 von Eddie Drapkin
On Wed, Aug 26, 2009 at 9:45 AM, hack988 hack988 wro=
te:
> I'm write a php file for you
> ==================== =====
=================3D
> define('Line_End', (PHP_OS == 'WINNT')?"\r\n":"\n");
> clearstatcache();
>
> $mylist=3Darray();
> listdir("F:\\Programming\\Web\\php",$mylist);
> function listdir($dir,&$list){
> Â if ($handle =3D opendir( $dir )){
> Â while ( false !== ( $item =3D readdir( $handle ) ) ) {
> Â Â if ( $item !=3D "." && $item !=3D ".." ) {
> Â Â Â Â Â $item=3Dstr_replace(Line_End,"",$item)=
;
> Â Â Â if ( is_dir( $dir.DIRECTORY_SEPARATOR.$item ) ) {
> Â Â Â Â listdir($dir.DIRECTORY_SEPARATOR.$item, $list=
);
> Â Â Â } else {
> Â Â Â Â $list[]=3D$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: Re: Directory Listing
am 26.08.2009 15:57:59 von 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: Re: Directory Listing
am 26.08.2009 17:34:16 von 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));
>> }
>> $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";
>> }
>> //print_r($files);
>> ?>
>>
>>
>> The output I'm getting is:
>> /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/Contents of Volumes 1 and 2.pdf 29/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 Questionnaire 14/08/2009
>> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls 13/05/2009
>> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls 13/05/2009
>> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls 13/05/2009
>> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls 13/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: Re: Directory Listing
am 26.08.2009 17:44:30 von hack988 hack988
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 =3D '.', $ignore =3D '') {
>>>>> =A0 =A0$dirTree =3D array ();
>>>>> =A0 =A0$dirTreeTemp =3D array ();
>>>>> =A0 =A0$fileDate =3D array ();
>>>>> =A0 =A0$ignore[] =3D '.';
>>>>> =A0 =A0$ignore[] =3D '..';
>>>>> =A0 =A0$dh =3D @opendir($path);
>>>>> =A0 =A0while (false !== ($file =3D readdir($dh))) {
>>>>> =A0 =A0 =A0 =A0if (!in_array($file, $ignore)) {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0if (!is_dir("$path/$file")) {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirTree["$path"][] =3D $file;
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$fileDate["$file"][] =3D date ("d/m/Y"=
,
>>>>> filemtime("$path/$file"));
>>>>> =A0 =A0 =A0 =A0 =A0 =A0} else {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirTreeTemp =3D getDirectory("$path/$=
file", $ignore);
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (is_array($dirTreeTemp))$dirTree =
=3D
>>>>> array_merge($dirTree, $dirTreeTemp, $fileDate);
>>>>> =A0 =A0 =A0 =A0 =A0 =A0}
>>>>> =A0 =A0 =A0 =A0}
>>>>> =A0 =A0}
>>>>> =A0 =A0closedir($dh);
>>>>> =A0 =A0return $dirTree;
>>>>> }
>>>>>
>>>>> $ignore =3D array('.htaccess', 'Thumbs.db', 'index.php');
>>>>> $dirTree =3D getDirectory('.', $ignore);
>>>>> getdirectory('.');
>>>>>
>>>>> echo "Gatwick Tender Documents\n";
>>>>>
>>>>> foreach( $dirTree as $key =3D> $folder ){
>>>>> =A0 echo "\n"; //Don't need folders as they're shown with the files
>>>>> =A0 foreach( $folder as $file){
>>>>> =A0 =A0 =A0 echo str_replace("./", "", $key) . "\t" . $file . "\t\n";=
//Pad
>>>>> out with a tab for easy import into excel
>>>>>
>>>>> =A0 }
>>>>> }
>>>>> 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
>>>>>
>>>>> . =A0 =A0 9216_100_REV_V1.0_bound.dwg
>>>>>
>>>>> Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
>>>>> Tender Docs =A0 Contents of Volumes 1 and 2.pdf
>>>>> Tender Docs =A0 Cover Letter and Instructions.doc
>>>>> Tender Docs =A0 Form of Tender.doc
>>>>>
>>>>> Tender Docs/Health and Safety Questionnaire =A0 NT Baggage Tender
>>>>> Questionaire rev2.xls
>>>>>
>>>>> BAA Works Terms v1.1 (22.05.08).pdf =A0 29/07/2009
>>>>>
>>>>> Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 29/07/2009
>>>>>
>>>>> Cover Letter and Instructions.doc =A0 =A0 29/07/2009
>>>>>
>>>>> Form of Tender.doc =A0 =A029/07/2009
>>>>>
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-1 PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-2B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-2R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-3R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-D PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4G-G PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-1B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-1R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-2B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-2R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-4 PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 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 whe=
re
>>>> the files were above 2GB each. When the files are that size, none of t=
he
>>>> 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) {
>>> =A0 =A0 =A0 =A0$array_items =3D array();
>>> =A0 =A0 =A0 =A0if ($handle =3D opendir($directory)) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0while (false !== ($file =3D readdir(=
$handle))) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ($file !=3D"index.php=
" && $file !=3D "." && $file
>>> !=3D "..") {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (is_d=
ir($directory. "/" . $file)) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0//For Directories
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0if($recursive) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0$array_items =3D
>>> array_merge($array_items,
>>> directoryToArray($directory. "/" . $file, $recursive));
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$fullfile =3D $directory . "/" .
>>> $file;
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$array_items[] =3D
>>> preg_replace("/\/\//si", "/", $fullfile);
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0//For Files
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$fullfile =3D $directory . "/" .
>>> $file;
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$array_items[] =3D
>>> preg_replace("/\/\//si", "/", $fullfile);
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0closedir($handle);
>>> =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0return $array_items;
>>> }
>>>
>>> $files =3D directoryToArray("./Tender", true);
>>>
>>>
>>> //Output to browser
>>> foreach ($files as $file) {
>>> =A0 =A0 =A0 =A0echo str_replace("./Tender", "", $file) . "\t" . " =A0 =
=A0 =A0" . date
>>> ("d/m/Y",
>>> filemtime($file)) . "\n";
>>> }
>>> //print_r($files);
>>> ?>
>>>
>>>
>>> The output I'm getting is:
>>> /9216_100_REV_V1.0_bound.dwg =A0 =A0 =A0 =A0 =A0 =A005/08/2009
>>> /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf
>>> =A029/07/2009
>>> /Tender Docs/Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 =A0 =A0 =A029/=
07/2009
>>> /Tender Docs/Cover Letter and Instructions.doc =A0 =A0 =A0 =A0 =A029/07=
/2009
>>> /Tender Docs/Form of Tender.doc =A0 =A0 =A0 =A0 29/07/2009
>>> /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender
>>> Questionaire rev2.xls =A0 =A0 =A0 =A0 =A0 29/07/2009
>>> /Tender Docs/Health and Safety Questionnaire =A0 =A0 =A0 =A0 =A0 =A014/=
08/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls =A0 =A0 =A0 =A0 =A0 =A0 13/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-D PIR.xls =A0 =A0 =A0 =A0 =A0 =A0 =A0 1=
3/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 =3D substr($file, strrpos('/')+1);
>> $directory =3D 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 th=
at.
> Though you will probably still run into the misplaced tabs if your paths
> don't have trailing slashes. At least it's cleaner.
>
> $filename =3D basename($file);
> $directory =3D 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
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: [SOLVED] Re: Directory Listing
am 26.08.2009 18:03:35 von Tom Chubb
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 =3D '.', $ignore =3D '') {
>>>>> =A0 =A0$dirTree =3D array ();
>>>>> =A0 =A0$dirTreeTemp =3D array ();
>>>>> =A0 =A0$fileDate =3D array ();
>>>>> =A0 =A0$ignore[] =3D '.';
>>>>> =A0 =A0$ignore[] =3D '..';
>>>>> =A0 =A0$dh =3D @opendir($path);
>>>>> =A0 =A0while (false !== ($file =3D readdir($dh))) {
>>>>> =A0 =A0 =A0 =A0if (!in_array($file, $ignore)) {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0if (!is_dir("$path/$file")) {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirTree["$path"][] =3D $file;
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$fileDate["$file"][] =3D date ("d/m/Y"=
,
>>>>> filemtime("$path/$file"));
>>>>> =A0 =A0 =A0 =A0 =A0 =A0} else {
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$dirTreeTemp =3D getDirectory("$path/$=
file", $ignore);
>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (is_array($dirTreeTemp))$dirTree =
=3D
>>>>> array_merge($dirTree, $dirTreeTemp, $fileDate);
>>>>> =A0 =A0 =A0 =A0 =A0 =A0}
>>>>> =A0 =A0 =A0 =A0}
>>>>> =A0 =A0}
>>>>> =A0 =A0closedir($dh);
>>>>> =A0 =A0return $dirTree;
>>>>> }
>>>>>
>>>>> $ignore =3D array('.htaccess', 'Thumbs.db', 'index.php');
>>>>> $dirTree =3D getDirectory('.', $ignore);
>>>>> getdirectory('.');
>>>>>
>>>>> echo "Gatwick Tender Documents\n";
>>>>>
>>>>> foreach( $dirTree as $key =3D> $folder ){
>>>>> =A0 echo "\n"; //Don't need folders as they're shown with the files
>>>>> =A0 foreach( $folder as $file){
>>>>> =A0 =A0 =A0 echo str_replace("./", "", $key) . "\t" . $file . "\t\n";=
//Pad
>>>>> out with a tab for easy import into excel
>>>>>
>>>>> =A0 }
>>>>> }
>>>>> 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
>>>>>
>>>>> . =A0 =A0 9216_100_REV_V1.0_bound.dwg
>>>>>
>>>>> Tender Docs =A0 BAA Works Terms v1.1 (22.05.08).pdf
>>>>> Tender Docs =A0 Contents of Volumes 1 and 2.pdf
>>>>> Tender Docs =A0 Cover Letter and Instructions.doc
>>>>> Tender Docs =A0 Form of Tender.doc
>>>>>
>>>>> Tender Docs/Health and Safety Questionnaire =A0 NT Baggage Tender
>>>>> Questionaire rev2.xls
>>>>>
>>>>> BAA Works Terms v1.1 (22.05.08).pdf =A0 29/07/2009
>>>>>
>>>>> Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 29/07/2009
>>>>>
>>>>> Cover Letter and Instructions.doc =A0 =A0 29/07/2009
>>>>>
>>>>> Form of Tender.doc =A0 =A029/07/2009
>>>>>
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-1 PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-2B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-2R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-B-3R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 3J-D PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4G-G PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-1B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-1R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-2B PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-2R PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 4J-B-4 PIR.xls
>>>>> Tender Docs/NTB BH Lighting =A0 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 whe=
re
>>>> the files were above 2GB each. When the files are that size, none of t=
he
>>>> 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) {
>>> =A0 =A0 =A0 =A0$array_items =3D array();
>>> =A0 =A0 =A0 =A0if ($handle =3D opendir($directory)) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0while (false !== ($file =3D readdir(=
$handle))) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ($file !=3D"index.php=
" && $file !=3D "." && $file
>>> !=3D "..") {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (is_d=
ir($directory. "/" . $file)) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0//For Directories
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0if($recursive) {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0$array_items =3D
>>> array_merge($array_items,
>>> directoryToArray($directory. "/" . $file, $recursive));
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$fullfile =3D $directory . "/" .
>>> $file;
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$array_items[] =3D
>>> preg_replace("/\/\//si", "/", $fullfile);
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else {
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0//For Files
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$fullfile =3D $directory . "/" .
>>> $file;
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0$array_items[] =3D
>>> preg_replace("/\/\//si", "/", $fullfile);
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0closedir($handle);
>>> =A0 =A0 =A0 =A0}
>>> =A0 =A0 =A0 =A0return $array_items;
>>> }
>>>
>>> $files =3D directoryToArray("./Tender", true);
>>>
>>>
>>> //Output to browser
>>> foreach ($files as $file) {
>>> =A0 =A0 =A0 =A0echo str_replace("./Tender", "", $file) . "\t" . " =A0 =
=A0 =A0" . date
>>> ("d/m/Y",
>>> filemtime($file)) . "\n";
>>> }
>>> //print_r($files);
>>> ?>
>>>
>>>
>>> The output I'm getting is:
>>> /9216_100_REV_V1.0_bound.dwg =A0 =A0 =A0 =A0 =A0 =A005/08/2009
>>> /Tender Docs/BAA Works Terms v1.1 (22.05.08).pdf
>>> =A029/07/2009
>>> /Tender Docs/Contents of Volumes 1 and 2.pdf =A0 =A0 =A0 =A0 =A0 =A029/=
07/2009
>>> /Tender Docs/Cover Letter and Instructions.doc =A0 =A0 =A0 =A0 =A029/07=
/2009
>>> /Tender Docs/Form of Tender.doc =A0 =A0 =A0 =A0 29/07/2009
>>> /Tender Docs/Health and Safety Questionnaire/NT Baggage Tender
>>> Questionaire rev2.xls =A0 =A0 =A0 =A0 =A0 29/07/2009
>>> /Tender Docs/Health and Safety Questionnaire =A0 =A0 =A0 =A0 =A0 =A014/=
08/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-1 PIR.xls =A0 =A0 =A0 =A0 =A0 =A0 13/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-2B PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-2R PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-B-3R PIR.xls =A0 =A0 =A0 =A0 =A0 =A013/=
05/2009
>>> /Tender Docs/NTB BH Lighting/3J-D PIR.xls =A0 =A0 =A0 =A0 =A0 =A0 =A0 1=
3/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 =3D substr($file, strrpos('/')+1);
>> $directory =3D 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 th=
at.
> Though you will probably still run into the misplaced tabs if your paths
> don't have trailing slashes. At least it's cleaner.
>
> $filename =3D basename($file);
> $directory =3D dirname($file);
>
> http://www.php.net/manual/function.basename.php
> http://www.php.net/manual/function.dirname.php
>
Thanks Steve - forgot about those!
I tried using dirname but I lost the "/" on files in the root so I
used this instead:
$filename =3D basename($file);
$path =3D str_replace ($filename, "", $file);
Working perfectly now. Here is the output which is exactly what I wanted:
(Path [tab] Filename [tab] Date Modified [tab] Filesize)
/Addendum 1/Hoare Lea
Drawings/ SPEC-0208660-013-2009-07-23-MWW-A32revA.pdf 05/08/2009 0.05
MB
/Addendum 1/Hoare Lea
Drawings/ SPEC-0208660-013-2009-07-23-MWW-A33revA.pdf 05/08/2009 0.07
MB
/Addendum 1/Industrial Relations/ Capital IR Policy Updated V2
200509.doc 06/08/2009 0.39 MB
/Addendum 1/Industrial Relations/ M&E Agreement April
2009.doc 06/08/2009 0.31 MB
/Addendum 1/Industrial Relations/ Presentation for Delivery Programmes
May 09.ppt 06/08/2009 0.8 MB
/Addendum 1/Logan dwgs/ 9216_014_REV_P03.dwg 19/05/2009 2.63 MB
/Addendum 1/Logan dwgs/ 9216_110_REV_V1.0_MH Scope.dwg 31/07/2009 5.64 MB
/Addendum 1/Logan dwgs 1/ 9216_014_REV_P03.dwg 19/05/2009 2.63 MB
/Addendum 1/Logan dwgs 1/ 9216_110_REV_V1.0_MH Scope.dwg 31/07/2009 5.64 MB
/Addendum 1/M & E Scope/ In and Out of Scope List 010509.ppt 06/08/2009 0.1=
3 MB
/Addendum 1/Manual Handling
Presentations/ Baggage_Handling_Lifting_Devices_for_BAA_20080922.ppt 22/09/=
2008 3.01
MB
/Addendum 1/Manual Handling Presentations/ Manual Handling systems
options presentation.pdf 11/05/2009 0.86 MB
Thanks for your help everyone.
Code is below if anyone is interested....
/*
This function will scan all files in the directory and all
sub-directories showing the path, filename and last modified date in
tabular format.
Copy the source files to scan onto the webserver and set the scan
directory when calling the function.
*/
error_reporting(E_ALL);
ini_set('display_errors', true);
function directoryToArray($directory, $recursive) {
$array_items =3D array();
if ($handle =3D opendir($directory)) {
while (false !== ($file =3D readdir($handle))) {
if ($file !=3D"index.php" && $file !=3D "." && $file !=3D "..") {
if (is_dir($directory. "/" . $file)) {
//For Directories
if($recursive) {
$array_items =3D array_merge($array_items,
directoryToArray($directory. "/" . $file, $recursive));
}
$fullfile =3D $directory . "/" . $file;
$array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
} else {
//For Files
$fullfile =3D $directory . "/" . $file;
$array_items[] =3D preg_replace("/\/\//si", "/", $fullfile);
}
}
}
closedir($handle);
}
return $array_items;
}
//Specify directory to scan and decide whether to scan recursively
$files =3D directoryToArray("./Tender", true);
//Output to browser and view source to copy/paste into excel
foreach ($files as $file) {
if (filesize($file) !== 0) {
$filesize =3D round(filesize($file)/1048576,2);
$filename =3D basename($file);
$path =3D str_replace ($filename, "", $file);
echo str_replace("./Tender", "", $path) . "\t" . strrpos('/', $file)
.. $filename . "\t" . date ("d/m/Y", filemtime($file)) . "\t" .
$filesize . " MB\n";
}
}
?>
--=20
Tom Chubb
tom@tomchubb.com | tomchubb@gmail.com
07912 202846
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php