Re: How would I get a list of all files matching a pattern?



On Feb 27, 5:06 pm, "Lars" <jon....@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"laredotornado" <laredotorn...@xxxxxxxxxxx> skrev i meddelandetnews:4ed42954-f370-4941-a6e8-bda6628b0b90@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi,

I'm using php 4.4.4.  Given a directory $dir, and a prefix, $prefix,
how would I get all files matching the expression

$dir/$prefix%d.jpg

where %d is any unsigned integer?

Thanks, - Dave

Don't know what you mean. Is it a string value or is it in the include part
where you include files. Assuming you wan't to build a strin use the
following.

I think the function sprintf solves your problem easally.

Seehttp://se2.php.net/manual/sv/function.sprintf.php

$aStringValue = sprintf("%s/%s%d\.jpg", $dir,$prefix, $number );
//  Don't knowif youca write a dot (.) after %d and get output as a dot.
//  Hence the %d\.. YOu might have to use \ before /. Test and see.

To build a sqeuence of HTML links to images do the following.

$text = sprintf("<table>\n");
$text .= sprintf("<tr><td><h1>Links to my images</h1></td></tr>\n");
for ($i=0;$i<$nbImages;$i++)
{
    $text .= sprintf("<tr><td><a href=\"%s/%s%d\.jpg\">Image
%3d</a></td></tr>\n", $dif, $prefix, $i );}

$text .= sprintf("</td></tr></table>\n");

//  Text holds the HTML list of links to the images.
//  Note %3d tells sprintf to writes $i as 001, 002, 003...

Lars

What I mean is let's say I have these files in a directory

/usr/local/apache2/htdocs/myfiles/file1.jpg
/usr/local/apache2/htdocs/myfiles/file2.jpg
/usr/local/apache2/htdocs/myfiles/file3.jpg
/usr/local/apache2/htdocs/myfiles/file4.jpg

The directory would be "/ur/local/apache2/htdocs/myfiles", the prefix
would be "file" and I'm looking for some way in PHP to return
"file1.jpg", "file2.jpg", "file3.jpg", and "file4.jpg", preferrably in
some kind of array.

Thanks, - Dave
.



Relevant Pages

  • Re: How would I get a list of all files matching a pattern?
    ... Given a directory $dir, and a prefix, $prefix, ... how would I get all files matching the expression ... To build a sqeuence of HTML links to images do the following. ...
    (alt.php)
  • Re: Loading image in Orca/Pascal
    ... necessary to load images using Orca - again, ... Also required is the P2GSString to convert the Pascal string into a GS/ ... if ToolError = 0 then begin ... srcHdl:= NewHandle(srcSize, ...
    (comp.sys.apple2.programmer)
  • Re: How to reference a Table in a Sub procedure
    ... If you have a table named Images in the current db then "SELECT * FROM ... make sure you assign your sql string to a variable: ... completed strSQL. ... figured out how passing the variables to the sub procedure works ...
    (microsoft.public.access.formscoding)
  • Re: storing path only to database
    ... is about 5gb..the type of file that i have to store is images ... cannot store all the images because of the limitation...now...i want to ... Dim MyFolder As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: how to set background of TD without an ID to none
    ... So whatever is assigned to the document.body.background attribute must be a string. ... table cell, but nothing instead, or second option, a transparent gif ... document.write which does something with images messes it up, ... happyimages = el.getElementsByTagName; ...
    (comp.lang.javascript)