note 106228 added to function.is-file
| From: | alcala_ruben2 at hotmail dot com | Date: | Wed, 19 Oct 2011 21:38:23 +0000 |
| Subject: | note 106228 added to function.is-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184009@lists.php.net to get a copy of this message | ||
This little script helps you get all php files (not hidden) inside certain folder including all
subfolders
<?php
$allDirs = array();
$dirLevel = 0;
$searchFactor = 0;
$searchPath = '';
$keepLooking = TRUE;
while ($keepLooking) {
if($dirLevel == 0){
$searchPath = '/path/to/parentFolder';
$tmp = array();
foreach (scandir($searchPath) as $filename) {
$host = $searchPath.'/'.$filename;
if (is_dir($host) && substr($filename,0,1)!='.'){
$searchFactor++;
array_push($tmp,$host);
}
elseif(is_file($host)) {
$forExt = explode('.',$host);
if($forExt[count($forExt)-1]=='php' &&
substr($filename,0,1)!='.')//if you want hidden files just take out the part
"&& substr($filename,0,1)!='.'"
echo $host;
}
}
if($searchFactor>0){
$dirLevel++;
array_push($allDirs, $tmp);
$searchFactor = 0;
}
}
else{
$tmp = array();
foreach ($allDirs[$dirLevel-1] as $searchPath) {
foreach (scandir($searchPath) as $filename) {
$host = $searchPath.'/'.$filename;
if (is_dir($host) && substr($filename,0,1)!='.'){
$searchFactor++;
array_push($tmp,$host);
}
elseif(is_file($host)) {
$forExt = explode('.',$host);
if($forExt[count($forExt)-1]=='php' &&
substr($filename,0,1)!='.')
echo $host;
}
}
}
if($searchFactor>0){
$dirLevel++;
array_push($allDirs, $tmp);
$searchFactor = 0;
}
else
$keepLooking = FALSE;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 190.222.188.132
----
Manual Page -- http://www.php.net/manual/en/function.is-file.php
Edit -- https://master.php.net/note/edit/106228
Del: integrated -- https://master.php.net/note/delete/106228/integrated
Del: useless -- https://master.php.net/note/delete/106228/useless
Del: bad code -- https://master.php.net/note/delete/106228/bad+code
Del: spam -- https://master.php.net/note/delete/106228/spam
Del: non-english -- https://master.php.net/note/delete/106228/non-english
Del: in docs -- https://master.php.net/note/delete/106228/in+docs
Del: other reasons-- https://master.php.net/note/delete/106228
Reject -- https://master.php.net/note/reject/106228
Search -- https://master.php.net/manage/user-notes.php