RE: Re: file_exists and wildcard/regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Boyd, Todd M. [mailto:tmboyd1@xxxxxxxx]
> Sent: Wednesday, December 10, 2008 8:28 AM
> To: php-general@xxxxxxxxxxxxx
> Subject: RE: Re:  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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux