Показать сообщение отдельно

  #11  
Старый 15.04.2009, 04:11
Pashkela
Динозавр
Регистрация: 10.01.2008
Сообщений: 2,841
Провел на форуме:
9220514

Репутация: 3338


По умолчанию

Цитата:
Сообщение от WebGer  
Ситуация такая.
На диске в каждой папке есть несколько под-под-папок.
В кажной из них лежит файл с одинаковым названием.
Нужно в цикле обойти все папки, и вытащить данные:
1. Название подпапки
2. Содержание этого файла.

я делал это на Delphi, но сейчас надо на php...
подскажите плиз как это можно сделать.
Способ дебильный, но примерно так:

PHP код:
<pre>
<?php 
@set_time_limit(0); 
@
ini_set("display_errors","1"); 

// Полный абсолютный путь до директории, в конце слеш не нужен 
$path '/home/www/bla-bla/http/s1';
$filename 'logfile.txt';
 
function 
fold($rootDir$allData=array()) {
    
$invisibleFileNames = array(".""..");
    
$dirContent scandir($rootDir);
    foreach(
$dirContent as $key => $content) {
        
$path $rootDir.'/'.$content;
        if(!
in_array($content$invisibleFileNames)) {
            if(
is_file($path) && is_readable($path)) {
                
preg_match('|\/(.*)\/|',$path,$res);
                
$allData[] = $res[0];
            }elseif(
is_dir($path) && is_readable($path)) {
                
$allData fold($path$allData);
            }
        }
    }
    return 
$allData;
}

$folders fold($path);
$count count($folders);
for (
$i=0;$i<$count;$i++) {
  
$handle fopen($folders[$i] . $filename"r"); 
  
$s fread($handlefilesize($folders[$i] . $filename)); 
  
fclose($handle);
  echo 
"File: " $folders[$i] . $filename "\n";
  echo 
"Content: " $s "\n";
}
?>
</pre>
 
Ответить с цитированием