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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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);

}

 

}

Link to comment
Share on other sites

<?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);

}

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.