how to find files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bruno storz

    #1

    how to find files

    Hit here,

    I am looking for an example how to select a or several files.

    I have a directory with a bunch of files. Now I want to use a form which
    allows me to enter some words which will be used to select files containing
    those words.

    Do you have any idea?

    Regards
    Bruno


  • Pedro Graca

    #2
    Re: how to find files

    bruno storz wrote:[color=blue]
    > I have a directory with a bunch of files. Now I want to use a form which
    > allows me to enter some words which will be used to select files containing
    > those words.[/color]

    grep


    1. get the words into an array
    2. grep foreach word in the files in the directory
    3. show results

    #v+

    <?php
    $filespec = '/var/www/htdocs/datadir/*';

    // 1
    $words = array('word1', 'word2');

    // 2
    $oneword = '';
    foreach ($words as $word) {
    $oneword .= `grep -li $word $filespec`;
    }
    $oneword = explode("\n", $oneword);
    $files = array_count_val ues($oneword);

    // 3
    foreach ($files as $file+>$dummy) {
    echo $file, "<br/>\n";
    }
    ?>

    #v-
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    Working...