help in php script
Posted: Wed Dec 03, 2008 3:03 pm
i am trying to read a folder and write its file names into excel.
here is script it works for small folder but my folder is in terabyte.
It is not able to open it for reading. is there any way to do so ?
<?php
ini_set("display_errors",1);
$ourDir = "C:/wamp/";
$d = dir($ourDir);
// prepare to read directory contents
$ourDirList = opendir($ourDir);
// loop through the items
$cntr=1;
$cnt = 1;
$ourFileName = "testFile1.csv";
while ($entry = readdir($ourDirList)) {
//if(is_dir($entry)){ // not always work
if(is_dir($ourDir."/".$entry)){ // always work
//echo "directory ".$cntr." is ==> $entry <br />";
if($cnt == 2){
$ourFileName = "testFile".$cntr++.".csv";
$cnt = 1;
}
$ourFileHandle = fopen($ourFileName, 'a+') or die("can't open file");
$data = $entry.",";
fwrite($ourFileHandle,$data);
fclose($ourFileHandle);
$cnt++;
$cntr++;
}
if (is_file($entry)){
// echo "file: $entry <br />";
}
}
$cntr = 0;
closedir($ourDirList);
?>
here is script it works for small folder but my folder is in terabyte.
It is not able to open it for reading. is there any way to do so ?
<?php
ini_set("display_errors",1);
$ourDir = "C:/wamp/";
$d = dir($ourDir);
// prepare to read directory contents
$ourDirList = opendir($ourDir);
// loop through the items
$cntr=1;
$cnt = 1;
$ourFileName = "testFile1.csv";
while ($entry = readdir($ourDirList)) {
//if(is_dir($entry)){ // not always work
if(is_dir($ourDir."/".$entry)){ // always work
//echo "directory ".$cntr." is ==> $entry <br />";
if($cnt == 2){
$ourFileName = "testFile".$cntr++.".csv";
$cnt = 1;
}
$ourFileHandle = fopen($ourFileName, 'a+') or die("can't open file");
$data = $entry.",";
fwrite($ourFileHandle,$data);
fclose($ourFileHandle);
$cnt++;
$cntr++;
}
if (is_file($entry)){
// echo "file: $entry <br />";
}
}
$cntr = 0;
closedir($ourDirList);
?>