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);
?>
help in php script
Moderator: General Moderators
- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: help in php script
Your code doesn't help much!! Please tell us more details of what you want to achieve, it seems like you are creating csv file for each folder encountered and with conditional check , are you trying to avoid the first directory encountered ??
Code: Select all
$cnt == 2I bet it worked only for the folder but not for fileskhalidanwar123 wrote:here is script it works for small folder
Last edited by novice4eva on Thu Dec 04, 2008 10:06 pm, edited 1 time in total.
-
khalidanwar123
- Forum Newbie
- Posts: 8
- Joined: Sun Nov 23, 2008 5:34 am
Re: help in php script
There is a folder containing millions of other folders in it,
Thus became a huge one ( in terabytes ) .
I'm trying to read the folder names within that. There is only 2 level directory structure.
One root folder and millions of folders in it.
The above code is an example what i am trying to do.
I do not require "." and ".." which i can put the check in future.
The actual thing i am trying to do is read a chunk of folder names from root folder and
and write it in a csv file.
The above code run successfully if the root folder is small in size.
But now it has become in terabytes , so i am not able to read it.
I want to know how i can open that folder to read its contents ( folder names ).
I hope you might have got the idea.
sorry about my poor English.
Thus became a huge one ( in terabytes ) .
I'm trying to read the folder names within that. There is only 2 level directory structure.
One root folder and millions of folders in it.
The above code is an example what i am trying to do.
I do not require "." and ".." which i can put the check in future.
The actual thing i am trying to do is read a chunk of folder names from root folder and
and write it in a csv file.
The above code run successfully if the root folder is small in size.
But now it has become in terabytes , so i am not able to read it.
I want to know how i can open that folder to read its contents ( folder names ).
I hope you might have got the idea.
sorry about my poor English.
- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: help in php script
Code: Select all
$ourDir = "C:/wamp/";
$ourDirList = opendir($ourDir);
$ourFileName = "testFile1.csv";
$ourFileHandle = fopen($ourFileName, 'a+') or die("can't open file");
while ($entry = readdir($ourDirList))
{
if(is_dir($ourDir."/".$entry) && ($entry!='.' || $entry!='..'))
$data.= $entry.",";
}
fwrite($ourFileHandle,$data);
fclose($ourFileHandle);
closedir($ourDirList);
-
khalidanwar123
- Forum Newbie
- Posts: 8
- Joined: Sun Nov 23, 2008 5:34 am
Re: help in php script
Thanks i will try this , if things did not work then i will think about c,c++ or java.