Asked 8 years ago
21 Dec 2016
Views 873
chirag

chirag posted

find all executable file at provided directory in php

want to get all executable file at provided directory in php.
using PHP for some local system. where i want to keep track of all files for particular directory.
so if i provide directory path than it should be give how many number of file is executable on that directory .

so i start to write code with scandir


$dir    = '/softwares';
$files1 = scandir($dir);
count($files1); 

count function give me count of all files not only count of executable files, so scandir not really scan the directory .
suppose is that possible i can put scandir(".exe,.sh") something like that so it can give me scanned result where only provided extension's file contained in list
or scandir("executable") give me only executable files . is that possible to use scandir like this? or any other solution to get executable files for given directory ?

testing with wamp .
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00


 $root="D:\software";
foreach (new DirectoryIterator($root) as $fileInfo) {
    if($fileInfo->isExecutable()) {
    echo $fileInfo->getFilename() . "<br>\n";
}
	}

testing at window will result
it give you all .exe files , not .dll , .php or .so or not .bat file

it means only find exe files not dll , php or so(linux) and .bat(batch file) .

Post Answer