Last active
May 8, 2023 00:24
-
-
Save fedmich/8ec847b559675914a4a91bb335697be3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fol = '/var/www/path'; | |
$files = preg_ls2( $fol, false, '@.*\.txt@i' ); | |
var_dump( $files ); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function preg_ls2 ($path=".", $rec=false, $pat="/.*/") { | |
$pat=preg_replace("|(/.*/[^S]*)|s", "\\1S", $pat); | |
while (substr($path,-1,1)=="/") $path=substr($path,0,-1); | |
if (!is_dir($path)) $path=dirname($path); | |
if ($rec!==true) $rec=false; | |
$d=dir($path); | |
$ret=Array(); | |
while (false!==($e=$d->read())) { | |
if (($e==".")||($e=="..")) continue; | |
if ($rec && is_dir($path."/".$e)) { | |
$ret=array_merge($ret,preg_ls($path."/".$e,$rec,$pat)); | |
continue; | |
} | |
if (!preg_match($pat,$e)) continue; | |
$ret[]=$e; | |
} | |
$d->close(); | |
return $ret; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment