newbie: scandir _not_ including directories

newbie: scandir _not_ including directories

am 30.12.2007 01:02:21 von unknown

Post removed (X-No-Archive: yes)

Re: newbie: scandir _not_ including directories

am 30.12.2007 03:35:02 von unknown

Post removed (X-No-Archive: yes)

Re: newbie: scandir _not_ including directories

am 03.01.2008 12:45:29 von Betikci Boris

On Dec 30 2007, 2:02 am, Jenny Purcell wrote:
> I have a function below that I (partially) wrote to handle a
> particular situation.
>
> I'm working with horse records in text files. I want to list all the
> files with horse information in them, then a dash "-", then, a brief
> description of the horse (taken from a separate text file). If that
> description isn't in the text file, it leaves a blank line (so I know
> to add it). The lines of extra information, as listed in separate
> file, do not have to be in any order.
>
> This all works:http://snowyriver.zzl.org/race_cards/index.php
>
> I find that that scandir() also scans for subdirectories. I _only_
> want to scan for .txt files. Scandir is good for me to use because it
> alphabetizes the files without any additional work.
>
> I would appreciate any help that could be offered as far as ways to
> adjust my $files array so it's only made up of .txt files.
>
> Thank you for reading this post!
>
> Jenny
>
>
>
> > // Links creating script taken from:http://www.phpfreaks.com/tutorials/146/0.php
> // Originally added October 21st, 2007
> // Modified by Jenny Purcell to be a subroutine to call it multiple
> times.
> // Further modified to include info on each horse from a separate file
> (by directory).
> //
>
> function make_links($dir,$breed) { // create a user-defined function
> named make_links
> $files = scandir($dir) ;
> $breedfile = @fopen("$breed","r",4096);
> $count = -1 ; // for array
> if ($breedfile) { // If file exists, execute while
> while (!feof($breedfile)) { // while we haven't reached
> the End of File, read lines into the buffer.
> $count = $count + 1 ; // increment
> // $horses[$count][1] = "";
> $horses[] = explode(" - ",fgets($breedfile)); //
> separate line elements into a 2 dimensional array
> } // close while
> fclose($breedfile); // close file when it reaches the EOF
> } // close if
> foreach($files as $ind_file){ // start outer foreach loop
> $letter = strtoupper(substr($ind_file,0,1));
> if($ind_file != '.' && $ind_file != '..') { // start
> 2nd if loop
> $count2 = -1 ;
> $temp = "";
> while ($count2 < $count) { // start inner foreach
> $count2 = $count2 + 1 ;
> if ($horses[$count2][0]== $ind_file) { //
> start 1st if loop
> $temp = $horses[$count2][1]; // temp
> is the info on the horse file
> } // end 1st if loop
> } // end inner foreach
> ?>
>

  • > href="">
    >

  • > > } // end 2nd if loop
    > } // end outer foreach loop
    >
    > } // end user-defined make_links function
    >
    > ?>
    >
    > --
    > Jenny Purcell
    > Snowy River Farms (PBEM Fantasy Horse Racing)http://snowyriver.zzl.org/

    Here is a sample code will guide you;
    This code scans within the chosen directory, returns the content which
    ends with "txt".

    $MySuggestion="Switch to MySQL buddie!;)";

    function isHorseTxt($filepath){

    $file=scandir("$filepath");
    $cf=count($file);
    for($i=0; $i<$cf; $i++){
    $istxt=substr("$file[$i]", 0, -3);
    if($istxt=="txt")
    echo("$file[$i]"); // i echoed here, or return
    something..
    }