Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP glob() doesnt find .htaccess

Simple question - How to list .htaccess files using glob()?

like image 752
Tony Bogdanov Avatar asked Dec 21 '11 18:12

Tony Bogdanov


1 Answers

glob() does list "hidden" files (files starting with . including the directories . and ..), but only if you explicitly ask it for:

 glob(".*");

Filtering the returned glob() array for .htaccess entries with preg_grep:

 $files = glob(".*") AND $files = preg_grep('/\.htaccess$/', $files);

The alternative to glob of course would be just using scandir() and a filter (fnmatch or regex):

 preg_grep('/^\.\w+/', scandir("."))
like image 149
mario Avatar answered Sep 29 '22 07:09

mario