Jump to content

[SOLVED] Create array(?) of subdirectory names, then do same action on same file in each


cgm225

Recommended Posts

I want to output an RSS feed based on text in identically named files located in different subdirectories (at the same level).  So the structure looks something like: /dir/subdir1/text.txt, /dir/subdir2/text.txt, /dir/subdir3/text.txt, etc.

 

Therefore, how can I create an array of these subdirectory names, and then loop through those directories to echo the text.txt content?

 

Thank you all in advance!

 

cgm225

Sorry..

 

I have photo albums (subdirectories) that have a text file (id.txt) with the title of the album in them.  I want to grab that information for each album, and then use it for an RSS feed I am creating.

 

Does that help?

 

 

Thanks again!

$handle = @fopen('yourfile...', "r");

if ($handle) {

  while (!feof($handle)) {

      $lines[] = fgets($handle, 4096);

  }

  fclose($handle);

}

 

or use file() function to have the text content in an array

 

try that

iy you have the array

if array are being set by u

 

 

foreach($array_dir as $dir)

{

$handle = @fopen('$dir', "r");

if ($handle) {

  while (!feof($handle)) {

      $lines[] = fgets($handle, 4096);

  }

  fclose($handle);

}

 

}

<?php

if ($handle = opendir('.')) {

    while (false !== ($file = readdir($handle))) {

        if ($file != "." && $file != "..") {

          // echo "$file\n";

        $handle = @fopen('$file', "r");

        if ($handle) {

            while (!feof($handle)) {

            $lines[] = fgets($handle, 4096);

          }

      fclose($handle);

}

        }

 

or try that

    }

    closedir($handle);

}

?>

i suggest use this

<?php

if ($handle = opendir('.')) {

    while (false !== ($file = readdir($handle))) {

        if ($file != "." && $file != "..") {

          // echo "$file\n";

        $handle = @fopen('$file', "r");

        if ($handle) {

            while (!feof($handle)) {

            $lines[] = fgets($handle, 4096);

          }

      fclose($handle);

}

        }

 

or try that

    }

    closedir($handle);

}

?>

thats better

 

$handle supply a dir for this

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.