RE: Re: [PHP] file_exists and wildcard/regex

From: Date: Wed, 10 Dec 2008 14:35:01 +0000
Subject: RE: Re: [PHP] file_exists and wildcard/regex
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-284418@lists.php.net to get a copy of this message
> -----Original Message----- > From: Boyd, Todd M. [mailto:tmboyd1@ccis.edu] > Sent: Wednesday, December 10, 2008 8:28 AM > To: php-general@lists.php.net > Subject: RE: Re: [PHP] file_exists and wildcard/regex > > FWIW, I would probably do the file search like this (UNTESTED): > > <?php > > $filereg = '/bfile[1-9]?\d+\.txt/i'; Erp. I meant '/bfile[1-9]?\d\.txt/i', with no '+' after the '\d'... assuming you want 0-99 to be the range of values. > $pathstr = '/whatever/your/path/is'; > > if(is_dir($pathstr)) { > if($dir = opendir($pathstr)) { > $found = false; > > while(($file = readdir($dir)) !== false && !$found) { > if(preg_match($filereg, $file) > 0) { > echo $file . '<br />'; > $found = true; > } > } > > closedir($dir); > } > } > > ?> // Todd

« previous php.general (#284418) next »