dini_Exists and dini_Create
#1

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

Bump, please help.
Reply
#3

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
Reply
#4

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

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

Thanks for the tip. I'll surely use it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)