PHP - List directories recursively and find files [duplicate]

1

Good morning everyone, I would like some help from the staff, I need to deliver a project in PHP and find myself stuck in a certain part of it, I need to recursively list all the directories that are inside "D: \" .

Example:

D:\diretorio01\backup001\

D:\diretorio02\backup002\
              \backup003\

D:\diretorio03\backup004\

And after listing the directories, I need to find all the .bak files inside them.

Is it possible to create this structure?

Thank you in advance for the support of all involved.

    
asked by anonymous 06.06.2018 / 14:47

1 answer

0

Yes, it is possible, just use the function glob :

foreach (glob('D:/**/*.bak') as $path) {
    echo $path, PHP_EOL;
}

It will fetch all files that have the .bak extension in any directory within D:/ .

    
06.06.2018 / 14:51