cgm225 Posted July 6, 2007 Share Posted July 6, 2007 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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/ Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 what??? explain more Link to comment https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291620 Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291623 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 $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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291629 Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 Thank you! How do I loop that action through all existing album directories? Link to comment https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291632 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291634 Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 Last question.. How do I create an array of those directories? Thank you so much! Link to comment https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291637 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 <?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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291638 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 the last sample are better but for your q $dir=array('dir1','dir2' .....etc) Link to comment https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291641 Share on other sites More sharing options...
cgm225 Posted July 6, 2007 Author Share Posted July 6, 2007 How do I get actually get the directory names for the array? Link to comment https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291642 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 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 https://forums.phpfreaks.com/topic/58780-solved-create-array-of-subdirectory-names-then-do-same-action-on-same-file-in-each/#findComment-291650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.