SA-MP Forums Archive
Loop trough ini files - 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: Loop trough ini files (/showthread.php?tid=332459)



Loop trough ini files - Jari_johnson - 08.04.2012

Like the title says, i'm curious if there is a way, to loop trough all files (.ini) in a folder, and search for a string in that file.

For example, if i want to trace the plate of a vehicle, the plates are saved in an INI file, and i want to /traceplate [plate number] and that it loops trough the files, and displays the information, like owner, position, veh.id and stuff..

Is this possible?


Re: Loop trough ini files - AndreT - 08.04.2012

If you don't know the file names, then no, without a plugin it is impossible to get a list of files that are in a folder. However if your naming scheme for vehicle files is something like 1.ini or 233.ini, then it is very well possible.

Simply use a loop, where you format a certain filename (e.g. "233.ini" as I mentioned), then check if the file exists. If it does, then get its plate number parameter and compare it to what the player wrote. If they match - great! If they don't, continue looking in other files.

However I can think of a major issue with this: time of execution. What I described will be hideously slow. I mean, seriously, quite slow. And if you're not satisfied with a slow function that can probably lag your server for even like 0.5 seconds (with thousands of files), MySQL/SQLite is your way to go.


Re: Loop trough ini files - Jstylezzz - 08.04.2012

Thanks, I will check this

(admins, could you please delete my Jari_johnson account? I only use Jari_Johnson* now )