Re: file_exists and wildcard/regex

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

 



On Tue, 2008-12-09 at 12:54 -1000, Daniel Kolbo wrote:
> 
> Daniel Kolbo wrote:
> > What is the preferred method with php to test and see if a file 
> > [pattern] exists?
> >
> > For example, i only need to search in one directory, that may have any 
> > number of files named such as afile1.txt, afile2.txt, afile3.txt, 
> > ....  And also, bfile1.txt, bfile2.txt, bfile3.txt, ...
> > I want to see if any such file 'family' exists.  That is, i want to 
> > see if there is any file named bfile[1-9][0-9]+.txt.  I don't care 
> > which bfile number exists, i just want to know if any bfile exists.
> >
> > I hope this is clear enough, if not let me know.
> >
> > thanks,
> > dK
> >
> After some more research it seems my options are:
> 1) loop through the directory contents
> 2) use scandir (then search the resulting array)
> 3) use glob.  I am not familiar with the glob pattern library, it does 
> not seem like i have the full power of regex when using glob is this 
> correct?  Also, searching the whole filesystem seems...overkill.
> 
> What do you suggest, is there a 4th option?
> thanks,
> dK
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.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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