Posts: 538
Threads: 62
Joined: Apr 2003
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]
[/url]
Posts: 3,343
Threads: 83
Joined: Mar 2003
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
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)
}
Posts: 538
Threads: 62
Joined: Apr 2003
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]
[/url]
Posts: 594
Threads: 11
Joined: Oct 2002
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
Posts: 538
Threads: 62
Joined: Apr 2003
thank you for your help
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79]
[/url]
Posts: 3,343
Threads: 83
Joined: Mar 2003
Quote:as in the title Quote:using PHP
Quote:But you get the idea You'll have to somehow convert that to PHP to make it work.
Posts: 538
Threads: 62
Joined: Apr 2003
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]
[/url]
Posts: 594
Threads: 11
Joined: Oct 2002
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