Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- search folders with array name


TheMadScientist - 1:36 am on Nov 7, 2009 (gmt 0)



for($i=2;$i<count($folders);$i++) {
if(is_dir($folders[$i])) {
if($dh = opendir($folders[$i])) {
while(($file = readdir($dh)) !== false) {
if($file == 'data.csv') {
echo "Eureka! I found data.csv in {$folders[$i]}";
break;
}
}
closedir($dh);
}
}
}

You've got two loops and one break()...
(This can be made more efficient after testing.)


for($i=2;$i<count($folders);$i++) {
if(is_dir($folders[$i])) {
if($dh = opendir($folders[$i])) {
while(($file = readdir($dh)) !== false) {
if($file == 'data.csv') {
echo "Eureka! I found data.csv in {$folders[$i]}";
break;
}
}
closedir($dh);
[b]if($file == 'data.csv') {
echo "Eureka! I found data.csv in {$folders[$i]}";
break;
}[/b]
}
}
}

@ JC: How are you getting the spacing for code on the forum? I tried using the code formatting and (obviously) it didn't work... How are you indenting? I don't want to have to find it myself (gettin' lazy or something). lol.


Thread source:: http://www.webmasterworld.com/php/4020548.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com