Greetings All!
Recently I've been hit by a strange problem while coding a
file indexing system. I have a source directory of the following
format:
/files/0-9
/files/0-9/0-90
/files/0-9/0-91
/files/a
/files/a/a0
/files/a/a1
/files/b
...
/file/z
ok you got the picture I hope. nothing difficult. now when i try
to exec my script, it hangs somewhere at path /files/a/a2 halting
right before it should switch to b0...
I'm including kinda long script below hoping some kind soul could
examine it and throw the errors i've made into my face.
I HOPE THIS IS NOT A BUG IN PHP.
<?
function dir_list($dirname)
{
$handle=opendir($dirname);
while (($file = readdir($handle))!==false)
{
if($file=='.'||$file=='..') continue;
$result_array[]=$dirname.$file;
}
closedir($handle);
return $result_array;
};
########################################################################
$HTMLDir="/WWW/htdocs/listss/";
$FileDir="/WWW/files/";
echo "<B><FONT FACE=verdana,arial,helvetica SIZE=-2>\n";
#Reset and Start the Timer.
$updated=0; $added=0; $removed=0; $total=0; $starttime =
doubleval(ereg_replace('^0\.([0-9]*) ([0-9]*)$','\\2.\\1',microtime()));
#Get Contents of main directory.
$D1=dir_list($FileDir);
#Cycle Through each subdir of $FileDir.
$S1=sizeof($D1);
for ($i1=0; $i1<$S1; $i1++)
{
#Check whether the current item is not a directory, report and die
if it is a file.
if (!is_dir($D1[$i1])) die("<FONT COLOR=#660000>ERROR 01:</FONT>
$D1[$i1] is a file, should be moved to a subdirectory.<BR>\n");
#CD into the current subdir.
$SubDir="$D1[$i1]/";
chdir($SubDir);
#Get contents of the current subdir.
$D2=dir_list($SubDir);
#Keep the name of current subdir in $CL
$CL=substr($D1[$i1],strrpos($D1[$i1],'/')+1);
#Print the header for the current directory.
echo "<BR><FONT SIZE=+1>";
if ($CL!="nm") echo strtoupper($CL); else echo "Numbers &
Symbols";
echo"</FONT><BR><HR NOSHADE SIZE=0 ALIGN=LEFT WIDTH=500>\n";
$S2=sizeof($D2);
for ($i2=0; $i2<$S2; $i2++)
{
#CD into the current subsubdir.
$SubSubDir="$D2[$i2]/";
echo "Entering $SubSubDir<BR>\n";
chdir($SubSubDir);
#Generate current HTML filename.
$CFL=substr($D2[$i2],strrpos($D2[$i2],'/')+1);
if (ereg("nm",$CFL)) $CFL=ereg_replace("nm","0-9",$CFL);
if (ereg("0-90",$CFL)) $CFL=ereg_replace("0-90","0-9",$CFL);
if ($CFL[1]=='0') $CFL=ereg_replace("0","",$CFL);
$CF="$HTMLDir$CFL.html";
#Open current HTML file.
echo " Writing to File $CF<BR>\n";
$fp=fopen($CF,'w');
#Get contents of the current subdir.
$D3=dir_list($SubSubDir);
$S3=sizeof($D3);
for ($j=0; $j<$S3; $j++)
{
echo "$D3[$j]<BR>\n";
};
#Close current HTML file.
echo " Closing File $CF<BR>\n";
fclose($fp);
#Return one level back,subletter listing.
echo "Returning to $SubDir<BR><BR>\n";
#chdir($SubDir);
};
#Return one level back, letter listing.
#chdir($FileDir);
};
#Get the finish time and printout the stats.
$endtime = doubleval(ereg_replace('^0\.([0-9]*)
([0-9]*)$','\\2.\\1',microtime()));
echo "<BR><BR><BR><FONT SIZE=+1>STATISTICS</FONT><BR><HR NOSHADE
ALIGN=LEFT SIZE=0 WIDTH=500>\n";
echo "Time Spent: <FONT COLOR=#660000>";
echo $endtime - $starttime;
echo "</FONT> sec<BR>\n";
echo "<BR><BR><BR><BR>";
?>
Thanks in advance
--
Vahan Yerkanian Email: [EMAIL PROTECTED]
Leading Web Developer / Designer Phone: (374) 158-2723
Web Development Department Fax: (374) 128-5082
ARMINCO Global Telecommunications http://www.arminco.com
--
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]