Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using PHP
#1
i have something that saves files with filenames that follow as 1.txt,2.txt,3.txt,4.txt,5.txt,6.txt,7.txt and so on. is there a way of printing the highest filename like out of that list it would print 7
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][Image: safer.gif][/url]
Reply
#2
In QB:

Code:
highestnum% = 15   ' Number you want to search from
FOR i% = highestnum% TO 0 STEP -1
  eye$ = STR$(i%)
  OPEN eye$ + ".txt" FOR APPEND AS #1
  IF LOF(1) < 3 THEN
    CLOSE #1
    KILL eye$ + ".txt"
  ELSE
    PRINT "The highest file name is: "; eye$ + ".txt"
    CLOSE #1
  END IF
NEXT i%

(Untested) But you get the idea Wink You'll have to somehow convert that to PHP to make it work.

Code:
for ($i = 15, $i = 1, $i--) {
  // Yada yada (fopen, fclose, unlink)
}
Reply
#3
as in the title
Quote:using PHP


and i don't know much about php at all thi is y first stab at it so please can you do a bit more of a fuller code please[/quote]
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][Image: safer.gif][/url]
Reply
#4
Here's a little example:

Code:
<?php

    $filenames = array();    //set up new array
    $file_num = 15;        //number of files
    $biggest_value = 0;    //array number of the biggest number

    // fill the array with the file numbers

    $filenames[0] = 7;
    $filenames[1] = 1;
    $filenames[2] = 10;
    $filenames[3] = 4;
    $filenames[4] = 14;
    $filenames[5] = 3;
    $filenames[6] = 8;
    $filenames[7] = 11;
    $filenames[8] = 9;
    $filenames[9] = 12;
    $filenames[10] = 13;
    $filenames[11] = 15;
    $filenames[12] = 2;
    $filenames[13] = 5;
    $filenames[14] = 6;


    for ($n = 0; $n < $file_num; $n++) {

        if ($filenames[$n] > $filenames[$biggest_value]) {

            $biggest_value = $n;

        }

    }

    echo 'The biggest value is '.$filenames[$biggest_value].' and is placed in array number '.$biggest_value;

?>
B 4 EVER
Reply
#5
thank you for your help
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][Image: safer.gif][/url]
Reply
#6
Quote:as in the title
Quote:using PHP

Quote:But you get the idea Wink You'll have to somehow convert that to PHP to make it work.

Smile
Reply
#7
i got this code form akooma and you have to fill in the filenames by hand

is there a way of getttig them to read the highest value there. like at the mni it is 3 but if i add another file then it will be wrong

you catch my drift
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][Image: safer.gif][/url]
Reply
#8
Here's the code:

Code:
<?php
$dir = ""; // Here you put the folder name, for example 'stuff'
$biggest_file="";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file > $biggest_file) {
                $biggest_file = $file;
            }
        }
        closedir($dh);
    }
}

print "The highest number is: ".$biggest_file;
?>

It reads all the filenames in the folder $dir and compares them. The highest one will be put into $biggest_file.
B 4 EVER
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)