SA-MP Forums Archive
Getting the highest index in folder - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting the highest index in folder (/showthread.php?tid=471108)



Getting the highest index in folder - AlonzoTorres - 21.10.2013

Let's say I have the following files in my directory:

Quote:

file_1
file_24
file_99
file_3
file_13

How can I get the highest index of that folder? In this case I'd want to get the "file_99" file.


Re: Getting the highest index in folder - RajatPawar - 21.10.2013

pawn Код:
new File: my_FILE,
      str[15],
      temp;
for( new i = 0; i < MAX_FILES; i++ )
{
     format(str, 15, "file_%d", i);
     my_FILE = fopen( str, io_read );
     if( my_FILE )
     {
           temp = i;
     }
     else continue;
}

MAXIMUM INDEX  =  temp;
I think something like this COULD work? I am not too experienced with files, TBH.


Re: Getting the highest index in folder - AlonzoTorres - 21.10.2013

Fixed, thank you Rajat.


AW: Getting the highest index in folder - BigETI - 21.10.2013

It's bad practice to store files, which should be indexed, like this. We don't know how many files do exist, so you can basicly create a loop going to 2^31, and make yourself coffee (and wait hours or days), while your script still searches for the highest "indexed file" in your directory.

You can use databases, which are just the best option to use for such purposes. Alternatively you can create a table of file names, where you can keep track of all the files inside this directory.