Loop trough ini files
#1

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?
Reply
#2

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.
Reply
#3

Thanks, I will check this

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


Forum Jump:


Users browsing this thread: 1 Guest(s)