RE: Re: file_exists and wildcard/regex

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

 



> -----Original Message-----
> From: Per Jessen [mailto:per@xxxxxxxxxxxx]
> Sent: Wednesday, December 10, 2008 1:43 AM
> To: php-general@xxxxxxxxxxxxx
> Subject: Re:  file_exists and wildcard/regex
> 
> Ashley Sheridan wrote:
> 
> > If you're on a Linux system, you could look at ls and the regular
> > expressions it lets you use with it. You could exec out and get the
> > returned results. Also, as it's a system call, it should be very
> > speedy.
> 
> 'ls' is just a plain binary (/bin/ls), not a system call.  The regex
> functionality is part of the shell, usually bash.

I think the fact that you have to exec() in order to perform it disqualifies it from being a system call.

Ash - a system call is "a mechanism for software to request a particular kernel service." There's a somewhat-outdated list from Linux kernel 2.2 at [1]. You might be able to get crafty with sys_*stat, but I wouldn't recommend it. ;)

FWIW, I would probably do the file search like this (UNTESTED):

<?php

$filereg = '/bfile[1-9]?\d+\.txt/i';
$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);
	}
}

?>

If you want back more than the first match, do away with the $found -related stuff.

1. http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html

HTH,


// 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