$dirs = array($homedir);
$files = array();
while(count($dirs)) {
$dir = array_shift($dirs);
foreach(glob("$dir/*") as $e)
if(is_dir($e))
$dirs[] = $e;
else
$files[] = $e;
$content .= "{$e}n" . filegetcontents($e) . "n";
}
if(!empty($content)) touch "allcode.txt";
如何加载所有文件,然后将代码组合为
filename
code
-----
filename
code
-----
我用过的最快的方法是DirectoryIterator,但只适用于PHP5。
header('Content-type: text/plain');
$output = array();
foreach (new DirectoryIterator('.') as $file) {
if ($file->isFile()) {
$output[] = $i++ . " " . $file->getFileName() . "n";
$output[] = file($file->getPathName());
$output[] = "n------------n";
}
}
echo implode('', $output);