Please give me a solution for get name of directories which doesn't contain file “input…” using php. My folder structure is like this:
Main Dir
namedirectory.php
Dir1
File1
input_1.txt
File
Dir2
File5
File6
Dir3
File1
input_2.txt
Dir4
File1
File2
Dir5
File1
File2
Because Dir1 and Dir3 has "input.." files, so it will get name=dir2,dir4,dir5. I have code but it doesn't work. Please help me fix it !
<?php
$dir ='/directory';
while($dirs = glob($dir . '/*', GLOB_ONLYDIR)) {
$dir .= '/*';
if(!$d) {
$d=$dirs;
} else {
$d=array_merge($d,$dirs);
}
foreach ($d as $d) {
if ($handle = opendir($d)) {
while ($entry = readdir($handle)) {
if (strpos($entry, "input") === FALSE) {
echo $d;
break;
}
}
closedir($handle);
}
}
}
?>
Use tripple = because PHP will cast false
to 0 which will be true.
Change:
if (strpos($entry, "input") == FALSE) {
Into
if (strpos($entry, "input") === FALSE) {
EDIT
$dir ='/directory';
while($dirs = glob($dir . '/*', GLOB_ONLYDIR)) {
$dir .= '/*';
if(!$d) {
$d=$dirs;
} else {
$d=array_merge($d,$dirs);
}
foreach ($d as $d) {
if ($handle = opendir($d)) {
$showDirectory = true;
while ($entry = readdir($handle)) {
if (strpos($entry, "input") !== FALSE) {
$showDirectory = false;
break;
}
}
if($showDirectory)
{
echo $d;
}
closedir($handle);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.