SA-MP Forums Archive
Counting files and creating a new - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Counting files and creating a new (/showthread.php?tid=201066)



Counting files and creating a new - Pooh7 - 20.12.2010

hi

How to make a script which will count files in folder, and create a new?
For example, I have 10 files in one folder. And all files has a name 1.ini, 2.ini, 3.ini.....10.ini.
So, how to count files in folder, or count numbers (1.ini, 2.ini ...) and create a new for one number bigger than previous?

Thanks, and sorry for my bad English


Re: Counting files and creating a new - iggy1 - 20.12.2010

Can't realy help unless we know what file system you use, for the native file functions (or most other file systems), you could do something simalar to this,
pawn Код:
new fcount;//global
#define MAX_FILES 50

for(new i = 1; i < MAX_FILES; i++)//note i initialised at 1 because thats what it said in ur post,
{                                 //if you have "0.ini" change it.
    new
        str[12];       
    format(str, 12, "%d.ini", i);
    if(fexist(str))
        fcount++;
    else
        break;
}
Now you can use "fcount" it will hold the number of the last file. To create a new one add one to its value, and use that result - as a name for the file. You could also put that in a function make "fcount" local to the function and use it as a return value.


Re: Counting files and creating a new - Pooh7 - 20.12.2010

Thanks man, I will try to use it


Re: Counting files and creating a new - iggy1 - 20.12.2010

Your welcome i hope it works for you. There are ways it could be made faster but thats the most simple way i could think of.