Jump to content

1 + 2 = 3 (add up of infinite text counter files)


ted_chou12

Recommended Posts

i have infinite number of files in a folder, and each of those txt files has a number, what i want is add all of those numbers together,
so far, this is what ive got
$namearray = array("forum"); // File names you want to exclude
$extarray = array("xml","jpg","php","css","bmp","png","html");  //extension you want to exclude
$files = array();
if ($handle = opendir(".")) {
  while (false !== ($file = readdir($handle))) {
    if($file != "." && $file != ".."){
      if (filetype($file) == "file" || filetype($file) == "dir"){
      $filearray = explode(".", $file);
      $files[$filearray[0]] = $filearray[1];
      }
    }
  }
closedir($handle);
}
foreach($files as $name => $ext){
  if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){
  } else {
  foreach(@file("homework/$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message) = explode("#",$v);}
  $repliesaa = file_get_contents("topic$number-replies.php")."\n";}


it lists out the txt files but i am having trouble adding the numbers up, can anyone give me some ideas
infinite number of files eh?  I need to get me one of those HD's ;)

Try this... count will hold your number of files.
[code]
...

$count = 0;

foreach($files as $name => $ext){

  ++ $count;

if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){
  } else {
  foreach(@file("homework/$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message) = explode("#",$v);}
  $repliesaa = file_get_contents("topic$number-replies.php")."\n";
}

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.