PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > Does anyone use Glob?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Does anyone use Glob?

Réponse
 
LinkBack Outils de la discussion
Vieux 15/11/2007, 08h48   #1
Mike
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Does anyone use Glob?

Hi

Does anyone use glob to search?. I am wondering how good/effective it is

http://de3.php.net/manual/en/function.glob.php


  Réponse avec citation
Vieux 15/11/2007, 14h09   #2
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Mike" <me@privacy.net> wrote in message
news:13jo2saj2oacnda@corp.supernews.com...
> Hi
>
> Does anyone use glob to search?. I am wondering how good/effective it is
>
> http://de3.php.net/manual/en/function.glob.php


i've been using it for years in the form of:


function listFiles($path = '.', $extension = array(), $combine = false)
{
$wd = getcwd();
$path .= substr($path, -1) != '/' ? '/' : '';
if (!chdir($path)){ return array(); }
if (!$extension){ $extension = array('*'); }
if (!is_array($extension)){ $extension = array($extension); }
$extensions = '*.{' . implode(',', $extension) . '}';
$files = glob($extensions, GLOB_BRACE);
chdir($wd);
if (!$files){ return array(); }
$list = array();
$path = $combine ? $path : '';
foreach ($files as $file)
{
$list[] = $path . $file;
}
return $list;
}


  Réponse avec citation
Vieux 16/11/2007, 15h57   #3
Tom Mackay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?

"Steve" <no.one@example.com> wrote in message
news:uqY_i.7$dY3.2@newsfe02.lga...
>
> "Mike" <me@privacy.net> wrote in message
> news:13jo2saj2oacnda@corp.supernews.com...
>> Hi
>>
>> Does anyone use glob to search?. I am wondering how good/effective it is
>>
>> http://de3.php.net/manual/en/function.glob.php

>
> i've been using it for years in the form of:
>
>
> function listFiles($path = '.', $extension = array(), $combine = false)
> {
> $wd = getcwd();
> $path .= substr($path, -1) != '/' ? '/' : '';
> if (!chdir($path)){ return array(); }
> if (!$extension){ $extension = array('*'); }
> if (!is_array($extension)){ $extension = array($extension); }
> $extensions = '*.{' . implode(',', $extension) . '}';
> $files = glob($extensions, GLOB_BRACE);
> chdir($wd);
> if (!$files){ return array(); }
> $list = array();
> $path = $combine ? $path : '';
> foreach ($files as $file)
> {
> $list[] = $path . $file;
> }
> return $list;
> }
>


Hi
I just tried your script but nothing happens. What is it supposed to do?


  Réponse avec citation
Vieux 16/11/2007, 16h18   #4
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Tom Mackay" <nospam@nospam.com> wrote in message
news:13jrfeiaa8dscca@corp.supernews.com...
> "Steve" <no.one@example.com> wrote in message
> news:uqY_i.7$dY3.2@newsfe02.lga...
>>
>> "Mike" <me@privacy.net> wrote in message
>> news:13jo2saj2oacnda@corp.supernews.com...
>>> Hi
>>>
>>> Does anyone use glob to search?. I am wondering how good/effective it
>>> is
>>>
>>> http://de3.php.net/manual/en/function.glob.php

>>
>> i've been using it for years in the form of:
>>
>>
>> function listFiles($path = '.', $extension = array(), $combine = false)
>> {
>> $wd = getcwd();
>> $path .= substr($path, -1) != '/' ? '/' : '';
>> if (!chdir($path)){ return array(); }
>> if (!$extension){ $extension = array('*'); }
>> if (!is_array($extension)){ $extension = array($extension); }
>> $extensions = '*.{' . implode(',', $extension) . '}';
>> $files = glob($extensions, GLOB_BRACE);
>> chdir($wd);
>> if (!$files){ return array(); }
>> $list = array();
>> $path = $combine ? $path : '';
>> foreach ($files as $file)
>> {
>> $list[] = $path . $file;
>> }
>> return $list;
>> }
>>

>
> Hi
> I just tried your script but nothing happens. What is it supposed to do?


list files in a directory...as in:

==============

<?
function listFiles($path = '.', $extension = array(), $combine = false)
{
$wd = getcwd();
$path .= substr($path, -1) != '/' ? '/' : '';
if (!chdir($path)){ return array(); }
if (!$extension){ $extension = array('*'); }
if (!is_array($extension)){ $extension = array($extension); }
$extensions = '*.{' . implode(',', $extension) . '}';
$files = glob($extensions, GLOB_BRACE);
chdir($wd);
if (!$files){ return array(); }
$list = array();
$path = $combine ? $path : '';
foreach ($files as $file)
{
$list[] = $path . $file;
}
return $list;
}
$files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
$images = array();
foreach ($files as $file)
{
$fileInfo = pathinfo($file);
$handle = fopen($file, 'r');
$fileInfo = array_merge($fileInfo, fstat($handle));
fclose($handle);
for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
echo '<pre>' . print_r($fileInfo, true) . '</pre>';
}
?>

==============

if you want to search for multiple extensions, then the listFiles arg would
be an array...as in:

array('jpg', 'gif', 'tif')

make sense?


  Réponse avec citation
Vieux 16/11/2007, 16h42   #5
Tom Mackay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Steve" <no.one@example.com> wrote in message
news:Spj%i.25$ug7.5@newsfe02.lga...
>
> "Tom Mackay" <nospam@nospam.com> wrote in message
> news:13jrfeiaa8dscca@corp.supernews.com...
>> "Steve" <no.one@example.com> wrote in message
>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>
>>> "Mike" <me@privacy.net> wrote in message
>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>> Hi
>>>>
>>>> Does anyone use glob to search?. I am wondering how good/effective it
>>>> is
>>>>
>>>> http://de3.php.net/manual/en/function.glob.php
>>>
>>> i've been using it for years in the form of:
>>>
>>>
>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>> {
>>> $wd = getcwd();
>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>> if (!chdir($path)){ return array(); }
>>> if (!$extension){ $extension = array('*'); }
>>> if (!is_array($extension)){ $extension = array($extension); }
>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>> $files = glob($extensions, GLOB_BRACE);
>>> chdir($wd);
>>> if (!$files){ return array(); }
>>> $list = array();
>>> $path = $combine ? $path : '';
>>> foreach ($files as $file)
>>> {
>>> $list[] = $path . $file;
>>> }
>>> return $list;
>>> }
>>>

>>
>> Hi
>> I just tried your script but nothing happens. What is it supposed to do?

>
> list files in a directory...as in:
>
> ==============
>
> <?
> function listFiles($path = '.', $extension = array(), $combine = false)
> {
> $wd = getcwd();
> $path .= substr($path, -1) != '/' ? '/' : '';
> if (!chdir($path)){ return array(); }
> if (!$extension){ $extension = array('*'); }
> if (!is_array($extension)){ $extension = array($extension); }
> $extensions = '*.{' . implode(',', $extension) . '}';
> $files = glob($extensions, GLOB_BRACE);
> chdir($wd);
> if (!$files){ return array(); }
> $list = array();
> $path = $combine ? $path : '';
> foreach ($files as $file)
> {
> $list[] = $path . $file;
> }
> return $list;
> }
> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
> $images = array();
> foreach ($files as $file)
> {
> $fileInfo = pathinfo($file);
> $handle = fopen($file, 'r');
> $fileInfo = array_merge($fileInfo, fstat($handle));
> fclose($handle);
> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
> }
> ?>
>
> ==============
>
> if you want to search for multiple extensions, then the listFiles arg
> would be an array...as in:
>
> array('jpg', 'gif', 'tif')
>
> make sense?



OK thanks.
FYI I have a similar list script i have been using for a while but
would like to replace this will a search instead of a full listing.
i.e. - search for file xxxx rather than going through the list to see if
it is present.

<?php
$path = "/usr/local/apache/share/default/";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
echo "<a href=\"$file\">$file</a><br />";
}
// Close
closedir($dir_handle);
?>

Any suggestions how to do this or point me in the right direction?.



  Réponse avec citation
Vieux 16/11/2007, 16h56   #6
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Tom Mackay" <nospam@nospam.com> wrote in message
news:13jri2nqr1phc22@corp.supernews.com...
>
> "Steve" <no.one@example.com> wrote in message
> news:Spj%i.25$ug7.5@newsfe02.lga...
>>
>> "Tom Mackay" <nospam@nospam.com> wrote in message
>> news:13jrfeiaa8dscca@corp.supernews.com...
>>> "Steve" <no.one@example.com> wrote in message
>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>
>>>> "Mike" <me@privacy.net> wrote in message
>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>> Hi
>>>>>
>>>>> Does anyone use glob to search?. I am wondering how good/effective it
>>>>> is
>>>>>
>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>
>>>> i've been using it for years in the form of:
>>>>
>>>>
>>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>>> {
>>>> $wd = getcwd();
>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>> if (!chdir($path)){ return array(); }
>>>> if (!$extension){ $extension = array('*'); }
>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>> $files = glob($extensions, GLOB_BRACE);
>>>> chdir($wd);
>>>> if (!$files){ return array(); }
>>>> $list = array();
>>>> $path = $combine ? $path : '';
>>>> foreach ($files as $file)
>>>> {
>>>> $list[] = $path . $file;
>>>> }
>>>> return $list;
>>>> }
>>>>
>>>
>>> Hi
>>> I just tried your script but nothing happens. What is it supposed to
>>> do?

>>
>> list files in a directory...as in:
>>
>> ==============
>>
>> <?
>> function listFiles($path = '.', $extension = array(), $combine = false)
>> {
>> $wd = getcwd();
>> $path .= substr($path, -1) != '/' ? '/' : '';
>> if (!chdir($path)){ return array(); }
>> if (!$extension){ $extension = array('*'); }
>> if (!is_array($extension)){ $extension = array($extension); }
>> $extensions = '*.{' . implode(',', $extension) . '}';
>> $files = glob($extensions, GLOB_BRACE);
>> chdir($wd);
>> if (!$files){ return array(); }
>> $list = array();
>> $path = $combine ? $path : '';
>> foreach ($files as $file)
>> {
>> $list[] = $path . $file;
>> }
>> return $list;
>> }
>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>> $images = array();
>> foreach ($files as $file)
>> {
>> $fileInfo = pathinfo($file);
>> $handle = fopen($file, 'r');
>> $fileInfo = array_merge($fileInfo, fstat($handle));
>> fclose($handle);
>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>> }
>> ?>
>>
>> ==============
>>
>> if you want to search for multiple extensions, then the listFiles arg
>> would be an array...as in:
>>
>> array('jpg', 'gif', 'tif')
>>
>> make sense?

>
>
> OK thanks.
> FYI I have a similar list script i have been using for a while but
> would like to replace this will a search instead of a full listing.
> i.e. - search for file xxxx rather than going through the list to see if
> it is present.
>
> <?php
> $path = "/usr/local/apache/share/default/";
> $dir_handle = @opendir($path) or die("Unable to open $path");
> while ($file = readdir($dir_handle)) {
> if($file == "." || $file == ".." || $file == "index.php" )
> continue;
> echo "<a href=\"$file\">$file</a><br />";
> }
> // Close
> closedir($dir_handle);
> ?>
>
> Any suggestions how to do this or point me in the right direction?.


from you example above:

$wd = getcwd();
chdir($path);
$files = glob('index.php');
chdir($wd);

that's it.

if you were so inclined, just modify my listFiles function at this line:

$extensions = '*.{' . implode(',', $extension) . '}';

to:

$extensions = '{' . implode(',', $extension) . '}';

i'd also change the variable names to $find (was $extension) and $search
(was $extensions). the only other change you'd need to note is when calling
the function. if searching by extension, you'd have to include the asterisk
yourself...

array('*.jpg', '*.png', 'index.php')

for example. that should list all jpg and png images and any file named
index.php. see if that works for you.


  Réponse avec citation
Vieux 16/11/2007, 16h59   #7
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Steve" <no.one@example.com> wrote in message
news:PYj%i.693$Xp7.184@newsfe05.lga...
>
> "Tom Mackay" <nospam@nospam.com> wrote in message
> news:13jri2nqr1phc22@corp.supernews.com...
>>
>> "Steve" <no.one@example.com> wrote in message
>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>
>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>> "Steve" <no.one@example.com> wrote in message
>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>
>>>>> "Mike" <me@privacy.net> wrote in message
>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>> Hi
>>>>>>
>>>>>> Does anyone use glob to search?. I am wondering how good/effective
>>>>>> it
>>>>>> is
>>>>>>
>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>
>>>>> i've been using it for years in the form of:
>>>>>
>>>>>
>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>> false)
>>>>> {
>>>>> $wd = getcwd();
>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>> if (!chdir($path)){ return array(); }
>>>>> if (!$extension){ $extension = array('*'); }
>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>> chdir($wd);
>>>>> if (!$files){ return array(); }
>>>>> $list = array();
>>>>> $path = $combine ? $path : '';
>>>>> foreach ($files as $file)
>>>>> {
>>>>> $list[] = $path . $file;
>>>>> }
>>>>> return $list;
>>>>> }
>>>>>
>>>>
>>>> Hi
>>>> I just tried your script but nothing happens. What is it supposed to
>>>> do?
>>>
>>> list files in a directory...as in:
>>>
>>> ==============
>>>
>>> <?
>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>> {
>>> $wd = getcwd();
>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>> if (!chdir($path)){ return array(); }
>>> if (!$extension){ $extension = array('*'); }
>>> if (!is_array($extension)){ $extension = array($extension); }
>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>> $files = glob($extensions, GLOB_BRACE);
>>> chdir($wd);
>>> if (!$files){ return array(); }
>>> $list = array();
>>> $path = $combine ? $path : '';
>>> foreach ($files as $file)
>>> {
>>> $list[] = $path . $file;
>>> }
>>> return $list;
>>> }
>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>> $images = array();
>>> foreach ($files as $file)
>>> {
>>> $fileInfo = pathinfo($file);
>>> $handle = fopen($file, 'r');
>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>> fclose($handle);
>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>> }
>>> ?>
>>>
>>> ==============
>>>
>>> if you want to search for multiple extensions, then the listFiles arg
>>> would be an array...as in:
>>>
>>> array('jpg', 'gif', 'tif')
>>>
>>> make sense?

>>
>>
>> OK thanks.
>> FYI I have a similar list script i have been using for a while but
>> would like to replace this will a search instead of a full listing.
>> i.e. - search for file xxxx rather than going through the list to see if
>> it is present.
>>
>> <?php
>> $path = "/usr/local/apache/share/default/";
>> $dir_handle = @opendir($path) or die("Unable to open $path");
>> while ($file = readdir($dir_handle)) {
>> if($file == "." || $file == ".." || $file == "index.php" )
>> continue;
>> echo "<a href=\"$file\">$file</a><br />";
>> }
>> // Close
>> closedir($dir_handle);
>> ?>
>>
>> Any suggestions how to do this or point me in the right direction?.

>
> from you example above:
>
> $wd = getcwd();
> chdir($path);
> $files = glob('index.php');
> chdir($wd);


btw, you know you DID NOT have that file in $path if !$files...as in:

if (!$files)
{
echo '<pre>index.php was not found in' . $path . '</pre>';
}


  Réponse avec citation
Vieux 16/11/2007, 17h06   #8
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Steve" <no.one@example.com> wrote in message
news:00k%i.694$Xp7.123@newsfe05.lga...
>
> "Steve" <no.one@example.com> wrote in message
> news:PYj%i.693$Xp7.184@newsfe05.lga...
>>
>> "Tom Mackay" <nospam@nospam.com> wrote in message
>> news:13jri2nqr1phc22@corp.supernews.com...
>>>
>>> "Steve" <no.one@example.com> wrote in message
>>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>>
>>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>>> "Steve" <no.one@example.com> wrote in message
>>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>>
>>>>>> "Mike" <me@privacy.net> wrote in message
>>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>>> Hi
>>>>>>>
>>>>>>> Does anyone use glob to search?. I am wondering how good/effective
>>>>>>> it
>>>>>>> is
>>>>>>>
>>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>>
>>>>>> i've been using it for years in the form of:
>>>>>>
>>>>>>
>>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>>> false)
>>>>>> {
>>>>>> $wd = getcwd();
>>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>>> if (!chdir($path)){ return array(); }
>>>>>> if (!$extension){ $extension = array('*'); }
>>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>>> chdir($wd);
>>>>>> if (!$files){ return array(); }
>>>>>> $list = array();
>>>>>> $path = $combine ? $path : '';
>>>>>> foreach ($files as $file)
>>>>>> {
>>>>>> $list[] = $path . $file;
>>>>>> }
>>>>>> return $list;
>>>>>> }
>>>>>>
>>>>>
>>>>> Hi
>>>>> I just tried your script but nothing happens. What is it supposed to
>>>>> do?
>>>>
>>>> list files in a directory...as in:
>>>>
>>>> ==============
>>>>
>>>> <?
>>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>>> {
>>>> $wd = getcwd();
>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>> if (!chdir($path)){ return array(); }
>>>> if (!$extension){ $extension = array('*'); }
>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>> $files = glob($extensions, GLOB_BRACE);
>>>> chdir($wd);
>>>> if (!$files){ return array(); }
>>>> $list = array();
>>>> $path = $combine ? $path : '';
>>>> foreach ($files as $file)
>>>> {
>>>> $list[] = $path . $file;
>>>> }
>>>> return $list;
>>>> }
>>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>>> $images = array();
>>>> foreach ($files as $file)
>>>> {
>>>> $fileInfo = pathinfo($file);
>>>> $handle = fopen($file, 'r');
>>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>>> fclose($handle);
>>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>>> }
>>>> ?>
>>>>
>>>> ==============
>>>>
>>>> if you want to search for multiple extensions, then the listFiles arg
>>>> would be an array...as in:
>>>>
>>>> array('jpg', 'gif', 'tif')
>>>>
>>>> make sense?
>>>
>>>
>>> OK thanks.
>>> FYI I have a similar list script i have been using for a while but
>>> would like to replace this will a search instead of a full listing.
>>> i.e. - search for file xxxx rather than going through the list to see
>>> if
>>> it is present.
>>>
>>> <?php
>>> $path = "/usr/local/apache/share/default/";
>>> $dir_handle = @opendir($path) or die("Unable to open $path");
>>> while ($file = readdir($dir_handle)) {
>>> if($file == "." || $file == ".." || $file == "index.php" )
>>> continue;
>>> echo "<a href=\"$file\">$file</a><br />";
>>> }
>>> // Close
>>> closedir($dir_handle);
>>> ?>
>>>
>>> Any suggestions how to do this or point me in the right direction?.

>>
>> from you example above:
>>
>> $wd = getcwd();
>> chdir($path);
>> $files = glob('index.php');
>> chdir($wd);

>
> btw, you know you DID NOT have that file in $path if !$files...as in:
>
> if (!$files)
> {
> echo '<pre>index.php was not found in' . $path . '</pre>';
> }


ROFL @ myself.

anyway, to expand this even further. if you modify the listFiles function as
i described, you can search for multiple files in a dir at one time and know
which WERE and were NOT found...like this:

$find = array('index.php', 'some.file.txt');
$found = listFiles($path, $find);
$missing = array_diff($find, $files);

that's the beauty of writing re-usable functions that are limited to single
tasks. it make building on or from them very easily done.

cheers


  Réponse avec citation
Vieux 16/11/2007, 17h06   #9
Tom Mackay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Steve" <no.one@example.com> wrote in message
news:PYj%i.693$Xp7.184@newsfe05.lga...
>
> "Tom Mackay" <nospam@nospam.com> wrote in message
> news:13jri2nqr1phc22@corp.supernews.com...
>>
>> "Steve" <no.one@example.com> wrote in message
>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>
>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>> "Steve" <no.one@example.com> wrote in message
>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>
>>>>> "Mike" <me@privacy.net> wrote in message
>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>> Hi
>>>>>>
>>>>>> Does anyone use glob to search?. I am wondering how good/effective
>>>>>> it
>>>>>> is
>>>>>>
>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>
>>>>> i've been using it for years in the form of:
>>>>>
>>>>>
>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>> false)
>>>>> {
>>>>> $wd = getcwd();
>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>> if (!chdir($path)){ return array(); }
>>>>> if (!$extension){ $extension = array('*'); }
>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>> chdir($wd);
>>>>> if (!$files){ return array(); }
>>>>> $list = array();
>>>>> $path = $combine ? $path : '';
>>>>> foreach ($files as $file)
>>>>> {
>>>>> $list[] = $path . $file;
>>>>> }
>>>>> return $list;
>>>>> }
>>>>>
>>>>
>>>> Hi
>>>> I just tried your script but nothing happens. What is it supposed to
>>>> do?
>>>
>>> list files in a directory...as in:
>>>
>>> ==============
>>>
>>> <?
>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>> {
>>> $wd = getcwd();
>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>> if (!chdir($path)){ return array(); }
>>> if (!$extension){ $extension = array('*'); }
>>> if (!is_array($extension)){ $extension = array($extension); }
>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>> $files = glob($extensions, GLOB_BRACE);
>>> chdir($wd);
>>> if (!$files){ return array(); }
>>> $list = array();
>>> $path = $combine ? $path : '';
>>> foreach ($files as $file)
>>> {
>>> $list[] = $path . $file;
>>> }
>>> return $list;
>>> }
>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>> $images = array();
>>> foreach ($files as $file)
>>> {
>>> $fileInfo = pathinfo($file);
>>> $handle = fopen($file, 'r');
>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>> fclose($handle);
>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>> }
>>> ?>
>>>
>>> ==============
>>>
>>> if you want to search for multiple extensions, then the listFiles arg
>>> would be an array...as in:
>>>
>>> array('jpg', 'gif', 'tif')
>>>
>>> make sense?

>>
>>
>> OK thanks.
>> FYI I have a similar list script i have been using for a while but
>> would like to replace this will a search instead of a full listing.
>> i.e. - search for file xxxx rather than going through the list to see if
>> it is present.
>>
>> <?php
>> $path = "/usr/local/apache/share/default/";
>> $dir_handle = @opendir($path) or die("Unable to open $path");
>> while ($file = readdir($dir_handle)) {
>> if($file == "." || $file == ".." || $file == "index.php" )
>> continue;
>> echo "<a href=\"$file\">$file</a><br />";
>> }
>> // Close
>> closedir($dir_handle);
>> ?>
>>
>> Any suggestions how to do this or point me in the right direction?.

>
> from you example above:
>
> $wd = getcwd();
> chdir($path);
> $files = glob('index.php');
> chdir($wd);
>
> that's it.
>
> if you were so inclined, just modify my listFiles function at this line:
>
> $extensions = '*.{' . implode(',', $extension) . '}';
>
> to:
>
> $extensions = '{' . implode(',', $extension) . '}';
>
> i'd also change the variable names to $find (was $extension) and $search
> (was $extensions). the only other change you'd need to note is when
> calling the function. if searching by extension, you'd have to include the
> asterisk yourself...
>
> array('*.jpg', '*.png', 'index.php')
>
> for example. that should list all jpg and png images and any file named
> index.php. see if that works for you.



The extension is always the same so i dont have to worry about that. How
would i include a search field into the script to allow me to enter the file
names into the page directly.
I am assuming this would be a normal form field?. i.e.

<form name="form" method="post" action="">
<label>search
<input type="text" name="textfield">
</label>


  Réponse avec citation
Vieux 16/11/2007, 17h15   #10
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Tom Mackay" <nospam@nospam.com> wrote in message
news:13jrjgd3uhctbff@corp.supernews.com...
>
> "Steve" <no.one@example.com> wrote in message
> news:PYj%i.693$Xp7.184@newsfe05.lga...
>>
>> "Tom Mackay" <nospam@nospam.com> wrote in message
>> news:13jri2nqr1phc22@corp.supernews.com...
>>>
>>> "Steve" <no.one@example.com> wrote in message
>>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>>
>>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>>> "Steve" <no.one@example.com> wrote in message
>>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>>
>>>>>> "Mike" <me@privacy.net> wrote in message
>>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>>> Hi
>>>>>>>
>>>>>>> Does anyone use glob to search?. I am wondering how good/effective
>>>>>>> it
>>>>>>> is
>>>>>>>
>>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>>
>>>>>> i've been using it for years in the form of:
>>>>>>
>>>>>>
>>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>>> false)
>>>>>> {
>>>>>> $wd = getcwd();
>>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>>> if (!chdir($path)){ return array(); }
>>>>>> if (!$extension){ $extension = array('*'); }
>>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>>> chdir($wd);
>>>>>> if (!$files){ return array(); }
>>>>>> $list = array();
>>>>>> $path = $combine ? $path : '';
>>>>>> foreach ($files as $file)
>>>>>> {
>>>>>> $list[] = $path . $file;
>>>>>> }
>>>>>> return $list;
>>>>>> }
>>>>>>
>>>>>
>>>>> Hi
>>>>> I just tried your script but nothing happens. What is it supposed to
>>>>> do?
>>>>
>>>> list files in a directory...as in:
>>>>
>>>> ==============
>>>>
>>>> <?
>>>> function listFiles($path = '.', $extension = array(), $combine = false)
>>>> {
>>>> $wd = getcwd();
>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>> if (!chdir($path)){ return array(); }
>>>> if (!$extension){ $extension = array('*'); }
>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>> $files = glob($extensions, GLOB_BRACE);
>>>> chdir($wd);
>>>> if (!$files){ return array(); }
>>>> $list = array();
>>>> $path = $combine ? $path : '';
>>>> foreach ($files as $file)
>>>> {
>>>> $list[] = $path . $file;
>>>> }
>>>> return $list;
>>>> }
>>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>>> $images = array();
>>>> foreach ($files as $file)
>>>> {
>>>> $fileInfo = pathinfo($file);
>>>> $handle = fopen($file, 'r');
>>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>>> fclose($handle);
>>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>>> }
>>>> ?>
>>>>
>>>> ==============
>>>>
>>>> if you want to search for multiple extensions, then the listFiles arg
>>>> would be an array...as in:
>>>>
>>>> array('jpg', 'gif', 'tif')
>>>>
>>>> make sense?
>>>
>>>
>>> OK thanks.
>>> FYI I have a similar list script i have been using for a while but
>>> would like to replace this will a search instead of a full listing.
>>> i.e. - search for file xxxx rather than going through the list to see
>>> if
>>> it is present.
>>>
>>> <?php
>>> $path = "/usr/local/apache/share/default/";
>>> $dir_handle = @opendir($path) or die("Unable to open $path");
>>> while ($file = readdir($dir_handle)) {
>>> if($file == "." || $file == ".." || $file == "index.php" )
>>> continue;
>>> echo "<a href=\"$file\">$file</a><br />";
>>> }
>>> // Close
>>> closedir($dir_handle);
>>> ?>
>>>
>>> Any suggestions how to do this or point me in the right direction?.

>>
>> from you example above:
>>
>> $wd = getcwd();
>> chdir($path);
>> $files = glob('index.php');
>> chdir($wd);
>>
>> that's it.
>>
>> if you were so inclined, just modify my listFiles function at this line:
>>
>> $extensions = '*.{' . implode(',', $extension) . '}';
>>
>> to:
>>
>> $extensions = '{' . implode(',', $extension) . '}';
>>
>> i'd also change the variable names to $find (was $extension) and $search
>> (was $extensions). the only other change you'd need to note is when
>> calling the function. if searching by extension, you'd have to include
>> the asterisk yourself...
>>
>> array('*.jpg', '*.png', 'index.php')
>>
>> for example. that should list all jpg and png images and any file named
>> index.php. see if that works for you.

>
>
> The extension is always the same so i dont have to worry about that. How
> would i include a search field into the script to allow me to enter the
> file names into the page directly.
> I am assuming this would be a normal form field?. i.e.
>
> <form name="form" method="post" action="">
> <label>search
> <input type="text" name="textfield">
> </label>


not sure i've ever seen <label> tags before.

anyway, yes, you could do it that way pretty easily. on the other side, you
would:

$find = $_REQUEST['textfield'];

and then do your search.

btw, you didn't mention recursion in your search...as in, if there is a sub
directory in $path, do you search for $file in that sub dir?


  Réponse avec citation
Vieux 16/11/2007, 17h27   #11
Tom Mackay
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Steve" <no.one@example.com> wrote in message
news:5fk%i.698$Xp7.594@newsfe05.lga...
>
> "Tom Mackay" <nospam@nospam.com> wrote in message
> news:13jrjgd3uhctbff@corp.supernews.com...
>>
>> "Steve" <no.one@example.com> wrote in message
>> news:PYj%i.693$Xp7.184@newsfe05.lga...
>>>
>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>> news:13jri2nqr1phc22@corp.supernews.com...
>>>>
>>>> "Steve" <no.one@example.com> wrote in message
>>>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>>>
>>>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>>>> "Steve" <no.one@example.com> wrote in message
>>>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>>>
>>>>>>> "Mike" <me@privacy.net> wrote in message
>>>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>>>> Hi
>>>>>>>>
>>>>>>>> Does anyone use glob to search?. I am wondering how good/effective
>>>>>>>> it
>>>>>>>> is
>>>>>>>>
>>>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>>>
>>>>>>> i've been using it for years in the form of:
>>>>>>>
>>>>>>>
>>>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>>>> false)
>>>>>>> {
>>>>>>> $wd = getcwd();
>>>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>>>> if (!chdir($path)){ return array(); }
>>>>>>> if (!$extension){ $extension = array('*'); }
>>>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>>>> chdir($wd);
>>>>>>> if (!$files){ return array(); }
>>>>>>> $list = array();
>>>>>>> $path = $combine ? $path : '';
>>>>>>> foreach ($files as $file)
>>>>>>> {
>>>>>>> $list[] = $path . $file;
>>>>>>> }
>>>>>>> return $list;
>>>>>>> }
>>>>>>>
>>>>>>
>>>>>> Hi
>>>>>> I just tried your script but nothing happens. What is it supposed to
>>>>>> do?
>>>>>
>>>>> list files in a directory...as in:
>>>>>
>>>>> ==============
>>>>>
>>>>> <?
>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>> false)
>>>>> {
>>>>> $wd = getcwd();
>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>> if (!chdir($path)){ return array(); }
>>>>> if (!$extension){ $extension = array('*'); }
>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>> chdir($wd);
>>>>> if (!$files){ return array(); }
>>>>> $list = array();
>>>>> $path = $combine ? $path : '';
>>>>> foreach ($files as $file)
>>>>> {
>>>>> $list[] = $path . $file;
>>>>> }
>>>>> return $list;
>>>>> }
>>>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>>>> $images = array();
>>>>> foreach ($files as $file)
>>>>> {
>>>>> $fileInfo = pathinfo($file);
>>>>> $handle = fopen($file, 'r');
>>>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>>>> fclose($handle);
>>>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>>>> }
>>>>> ?>
>>>>>
>>>>> ==============
>>>>>
>>>>> if you want to search for multiple extensions, then the listFiles arg
>>>>> would be an array...as in:
>>>>>
>>>>> array('jpg', 'gif', 'tif')
>>>>>
>>>>> make sense?
>>>>
>>>>
>>>> OK thanks.
>>>> FYI I have a similar list script i have been using for a while but
>>>> would like to replace this will a search instead of a full listing.
>>>> i.e. - search for file xxxx rather than going through the list to see
>>>> if
>>>> it is present.
>>>>
>>>> <?php
>>>> $path = "/usr/local/apache/share/default/";
>>>> $dir_handle = @opendir($path) or die("Unable to open $path");
>>>> while ($file = readdir($dir_handle)) {
>>>> if($file == "." || $file == ".." || $file == "index.php" )
>>>> continue;
>>>> echo "<a href=\"$file\">$file</a><br />";
>>>> }
>>>> // Close
>>>> closedir($dir_handle);
>>>> ?>
>>>>
>>>> Any suggestions how to do this or point me in the right direction?.
>>>
>>> from you example above:
>>>
>>> $wd = getcwd();
>>> chdir($path);
>>> $files = glob('index.php');
>>> chdir($wd);
>>>
>>> that's it.
>>>
>>> if you were so inclined, just modify my listFiles function at this line:
>>>
>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>
>>> to:
>>>
>>> $extensions = '{' . implode(',', $extension) . '}';
>>>
>>> i'd also change the variable names to $find (was $extension) and $search
>>> (was $extensions). the only other change you'd need to note is when
>>> calling the function. if searching by extension, you'd have to include
>>> the asterisk yourself...
>>>
>>> array('*.jpg', '*.png', 'index.php')
>>>
>>> for example. that should list all jpg and png images and any file named
>>> index.php. see if that works for you.

>>
>>
>> The extension is always the same so i dont have to worry about that.
>> How would i include a search field into the script to allow me to enter
>> the file names into the page directly.
>> I am assuming this would be a normal form field?. i.e.
>>
>> <form name="form" method="post" action="">
>> <label>search
>> <input type="text" name="textfield">
>> </label>

>
> not sure i've ever seen <label> tags before.
>
> anyway, yes, you could do it that way pretty easily. on the other side,
> you would:
>
> $find = $_REQUEST['textfield'];
>
> and then do your search.
>
> btw, you didn't mention recursion in your search...as in, if there is a
> sub directory in $path, do you search for $file in that sub dir?




Yes would like to have the sub directories included.
Thanks for the info above. I will have a read over what you have posted
and will see if i can put it together and get it to work.
I'm not as knowledgeable as you though so will probably take me a while


  Réponse avec citation
Vieux 16/11/2007, 18h05   #12
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does anyone use Glob?


"Tom Mackay" <nospam@nospam.com> wrote in message
news:13jrknk5st2n2a4@corp.supernews.com...
>
> "Steve" <no.one@example.com> wrote in message
> news:5fk%i.698$Xp7.594@newsfe05.lga...
>>
>> "Tom Mackay" <nospam@nospam.com> wrote in message
>> news:13jrjgd3uhctbff@corp.supernews.com...
>>>
>>> "Steve" <no.one@example.com> wrote in message
>>> news:PYj%i.693$Xp7.184@newsfe05.lga...
>>>>
>>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>>> news:13jri2nqr1phc22@corp.supernews.com...
>>>>>
>>>>> "Steve" <no.one@example.com> wrote in message
>>>>> news:Spj%i.25$ug7.5@newsfe02.lga...
>>>>>>
>>>>>> "Tom Mackay" <nospam@nospam.com> wrote in message
>>>>>> news:13jrfeiaa8dscca@corp.supernews.com...
>>>>>>> "Steve" <no.one@example.com> wrote in message
>>>>>>> news:uqY_i.7$dY3.2@newsfe02.lga...
>>>>>>>>
>>>>>>>> "Mike" <me@privacy.net> wrote in message
>>>>>>>> news:13jo2saj2oacnda@corp.supernews.com...
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> Does anyone use glob to search?. I am wondering how
>>>>>>>>> good/effective it
>>>>>>>>> is
>>>>>>>>>
>>>>>>>>> http://de3.php.net/manual/en/function.glob.php
>>>>>>>>
>>>>>>>> i've been using it for years in the form of:
>>>>>>>>
>>>>>>>>
>>>>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>>>>> false)
>>>>>>>> {
>>>>>>>> $wd = getcwd();
>>>>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>>>>> if (!chdir($path)){ return array(); }
>>>>>>>> if (!$extension){ $extension = array('*'); }
>>>>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>>>>> chdir($wd);
>>>>>>>> if (!$files){ return array(); }
>>>>>>>> $list = array();
>>>>>>>> $path = $combine ? $path : '';
>>>>>>>> foreach ($files as $file)
>>>>>>>> {
>>>>>>>> $list[] = $path . $file;
>>>>>>>> }
>>>>>>>> return $list;
>>>>>>>> }
>>>>>>>>
>>>>>>>
>>>>>>> Hi
>>>>>>> I just tried your script but nothing happens. What is it supposed
>>>>>>> to do?
>>>>>>
>>>>>> list files in a directory...as in:
>>>>>>
>>>>>> ==============
>>>>>>
>>>>>> <?
>>>>>> function listFiles($path = '.', $extension = array(), $combine =
>>>>>> false)
>>>>>> {
>>>>>> $wd = getcwd();
>>>>>> $path .= substr($path, -1) != '/' ? '/' : '';
>>>>>> if (!chdir($path)){ return array(); }
>>>>>> if (!$extension){ $extension = array('*'); }
>>>>>> if (!is_array($extension)){ $extension = array($extension); }
>>>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>>> $files = glob($extensions, GLOB_BRACE);
>>>>>> chdir($wd);
>>>>>> if (!$files){ return array(); }
>>>>>> $list = array();
>>>>>> $path = $combine ? $path : '';
>>>>>> foreach ($files as $file)
>>>>>> {
>>>>>> $list[] = $path . $file;
>>>>>> }
>>>>>> return $list;
>>>>>> }
>>>>>> $files = listFiles('c:/inetpub/wwwroot/images', 'jpg', true);
>>>>>> $images = array();
>>>>>> foreach ($files as $file)
>>>>>> {
>>>>>> $fileInfo = pathinfo($file);
>>>>>> $handle = fopen($file, 'r');
>>>>>> $fileInfo = array_merge($fileInfo, fstat($handle));
>>>>>> fclose($handle);
>>>>>> for ($i = 0; $i < 13; $i++){ unset($fileInfo[$i]); }
>>>>>> echo '<pre>' . print_r($fileInfo, true) . '</pre>';
>>>>>> }
>>>>>> ?>
>>>>>>
>>>>>> ==============
>>>>>>
>>>>>> if you want to search for multiple extensions, then the listFiles arg
>>>>>> would be an array...as in:
>>>>>>
>>>>>> array('jpg', 'gif', 'tif')
>>>>>>
>>>>>> make sense?
>>>>>
>>>>>
>>>>> OK thanks.
>>>>> FYI I have a similar list script i have been using for a while but
>>>>> would like to replace this will a search instead of a full listing.
>>>>> i.e. - search for file xxxx rather than going through the list to see
>>>>> if
>>>>> it is present.
>>>>>
>>>>> <?php
>>>>> $path = "/usr/local/apache/share/default/";
>>>>> $dir_handle = @opendir($path) or die("Unable to open $path");
>>>>> while ($file = readdir($dir_handle)) {
>>>>> if($file == "." || $file == ".." || $file == "index.php" )
>>>>> continue;
>>>>> echo "<a href=\"$file\">$file</a><br />";
>>>>> }
>>>>> // Close
>>>>> closedir($dir_handle);
>>>>> ?>
>>>>>
>>>>> Any suggestions how to do this or point me in the right direction?.
>>>>
>>>> from you example above:
>>>>
>>>> $wd = getcwd();
>>>> chdir($path);
>>>> $files = glob('index.php');
>>>> chdir($wd);
>>>>
>>>> that's it.
>>>>
>>>> if you were so inclined, just modify my listFiles function at this
>>>> line:
>>>>
>>>> $extensions = '*.{' . implode(',', $extension) . '}';
>>>>
>>>> to:
>>>>
>>>> $extensions = '{' . implode(',', $extension) . '}';
>>>>
>>>> i'd also change the variable names to $find (was $extension) and
>>>> $search (was $extensions). the only other change you'd need to note is
>>>> when calling the function. if searching by extension, you'd have to
>>>> include the asterisk yourself...
>>>>
>>>> array('*.jpg', '*.png', 'index.php')
>>>>
>>>> for example. that should list all jpg and png images and any file named
>>>> index.php. see if that works for you.
>>>
>>>
>>> The extension is always the same so i dont have to worry about that. How
>>> would i include a search field into the script to allow me to enter the
>>> file names into the page directly.
>>> I am assuming this would be a normal form field?. i.e.
>>>
>>> <form name="form" method="post" action="">
>>> <label>search
>>> <input type="text" name="textfield">
>>> </label>

>>
>> not sure i've ever seen <label> tags before.
>>
>> anyway, yes, you could do it that way pretty easily. on the other side,
>> you would:
>>
>> $find = $_REQUEST['textfield'];
>>
>> and then do your search.
>>
>> btw, you didn't mention recursion in your search...as in, if there is a
>> sub directory in $path, do you search for $file in that sub dir?

>
>
>
> Yes would like to have the sub directories included.
> Thanks for the info above. I will have a read over what you have posted
> and will see if i can put it together and get it to work.
> I'm not as knowledgeable as you though so will probably take me a while


just look over the php functions used. the guts of it are here:

>>>> $wd = getcwd();
>>>> chdir($path);
>>>> $files = glob('index.php');
>>>> chdir($wd);


notice, i use GLOB_BRACE...look in the manual for why and you'll be golden.
as for directory recursion, let me know if you get stuck. is_dir() will
as a hint...but you'll probably find many examples just by googling.

cheers.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,45161 seconds with 20 queries