dini_Exists and dini_Create - 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: dini_Exists and dini_Create (
/showthread.php?tid=444298)
dini_Exists and dini_Create -
hbzi - 16.06.2013
Hey everyone.
I'd like to have a function that checks what's the last file in a folder with files ordered from 0.ini to n.ini where n is the last file (0.ini, 1.ini, 2.ini .. n.ini). The goal is to create a file called n+1.ini.
I'd be glad if you could help,
hbzi.
Re: dini_Exists and dini_Create -
hbzi - 16.06.2013
Bump, please help.
AW: dini_Exists and dini_Create -
Nero_3D - 16.06.2013
Loop through the files at OnGameModeInit and save the last number in a global variable
pawn Код:
new
gNextFileID = -1
;
// OnGameModeInit
new
tmp[16]
;
do {
format(tmp, sizeof tmp, "%d.ini", ++gNextFileID);
} while(fexist(tmp));
Than whenever you create a new file increase the counter
Re: dini_Exists and dini_Create -
hbzi - 17.06.2013
Thanks but I've already figured it out.
Did it this way:
pawn Код:
#define MAX_FILES 100 // Just a number that I know it's bigger than the number of files in the folder
stock LastFile()
{
new file[16];
new i;
for (i=1; i<MAX_FILES; i++)
{
format(file, sizeof(file), "folder/%d.ini", i);
if(!dini_Exists(file)) return i;
}
return 1;
}
I'm not sure whether this way is faster or not but it works.
Re: dini_Exists and dini_Create -
Pottus - 17.06.2013
Instead of doing that hbzi do it like this.....
pawn Код:
#define LastFile() FileCount
new FileCount;
public OnGameModeInit()
{
UpdateFileCount();
}
stock UpdateFileCount()
{
new file[16];
new i;
for (i=1; i<MAX_FILES; i++)
{
format(file, sizeof(file), "folder/%d.ini", i);
if(!dini_Exists(file)) break;
FileCount++;
}
}
That way you only have to UpdateFileCount(); when you add/remove it will be more efficient.
Re: dini_Exists and dini_Create -
hbzi - 17.06.2013
Thanks for the tip. I'll surely use it.