SA-MP Forums Archive
Collecting all files in a directory. - 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: Collecting all files in a directory. (/showthread.php?tid=444751)



Collecting all files in a directory. - kin - 18.06.2013

I need to get the file name of all the files in a specific folder/directory. This poses a problem because you cannot easily achieve this considering there are not any functions to handle this in pawn or in y_ini (the file system I'm using). So I looked around for a plugin, but this plugin was bugged and out dated so I could not use this. So my question is, how can I iterate through a directory and collect all the files/file names into one array so I can display it and use the collected data. Thanks in advance for the help, or attempts of help.


Re: Collecting all files in a directory. - MP2 - 18.06.2013

You'll have to use one of the file plugins. There's no functionality for this in pawn.


Re: Collecting all files in a directory. - Ballu Miaa - 18.06.2013

I always had problems doing this too therefore i first switched to SQLite and then MYSQL. Quering everything is easy and efficient.


Re: Collecting all files in a directory. - kin - 18.06.2013

Does it create a local database, or do I need to have a server?


Re: Collecting all files in a directory. - kin - 18.06.2013

Still need help.


Re: Collecting all files in a directory. - MP2 - 18.06.2013

Quote:
Originally Posted by MP2
View Post
You'll have to use one of the file plugins. There's no functionality for this in pawn.



Re: Collecting all files in a directory. - Pooh7 - 18.06.2013

There are multiple file plugins on the forums. If you have problem with the one you tried, try another.



If your files are numbered and are in format e.g. "1.ini", than you can make a loop like this:

pawn Code:
for (new i = 1, filename[12]; i <= 100; i++) // replace "100" with the maximum number you have in the directory
{
    format(filename, sizeof(filename), "%d.ini", i);

    if (fexist(filename))
    {
        // file exists, do whatever you want here
    }
    else continue;
}
If your files are not numbered, than you'll have to use a plugin.


Re: Collecting all files in a directory. - kin - 18.06.2013

I must have skipped over the plugins then, Ill go search even more.