Re: Traverse directory - Find empty directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi
Thank you for answering my question Jim.
I didn't notice the message get into the list because I get errors when 
posting and then I quit to post and try to solve the problem. Your solution 
is good and nice. I used scandir() instead of glob() with a recursive 
function.

Best regards
holo


"Jim Lucas" <lists@xxxxxxxxx> wrote in message 
news:47C701FC.2020202@xxxxxxxxxxxx
> Holografix wrote:
>> Hi
>>
>> I'm using Spl RecursiveDirectoryIterator to traverse a directory and have 
>> no problem with it but now I'm stuck. I only need to display directories 
>> with no files in it.
>>
>> Can someone help with this?
>>
>> My current code:
>>
>> set_time_limit(0);
>>
>> $files = new RecursiveIteratorIterator(new 
>> RecursiveDirectoryIterator('c:\dev'), 
>> RecursiveIteratorIterator::SELF_FIRST);
>> foreach($files as $file) {
>>     if ($files->isDir()) {
>>         echo $file . "<br/>";
>>     }
>> }
>>
>> I have
>> c:\dev
>> c:\dev\php
>> c:\dev\php\file1.php
>> c:\dev\php\file2.php
>> c:\dev\php\test
>> c:\dev\php\test\db
>>
>> I would like to display 'test' because although there is a 'db'  folder, 
>> there are no files in c:\dev\php\test
>>
>>
>>
>> Bets regards,
>> holo
>
> This should do what you are looking to do.
>
> Someone else might find a better way of doing it, but this will work.
>
> <?php
>
> set_time_limit(0);
>
> $path = './';
>
> $files = new RecursiveIteratorIterator(new 
> RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
> foreach($files as $file) {
> if ($files->isDir()) {
> if ( ( $results = glob($file.'/*') ) !== false ) {
> $file_found = false;
> foreach ( $results AS $entry ) {
> if ( is_file($entry) ) {
> $file_found = true;
> break;
> }
> }
>
> if ( !$file_found )
> echo $file . " DOES NOT contain files\n";
>
> }
> }
> }
>
>
> -- 
> Jim Lucas
>
>    "Some men are born to greatness, some achieve greatness,
>        and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>     by William Shakespeare 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux