Rename y_ini file
#1

What's the best way to rename a y_ini file and keep the data? I searched through the y_ini and couldn't find a straight frename function.
Reply
#2

pawn Код:
stock frename(oldname[], newname[])
{
    if(!fexist(oldname)) return 1;
    new string[128], File:older, File:newer;
    older = fopen(oldname, io_read);
    newer = fopen(newname, io_write);
    while(fread(older, string))
    {
        StripNewLine(string);
        format(string, sizeof(string), "%s\r\n", string);
        fwrite(newer, string);
    }
    fclose(older);
    fclose(newer);
    fremove(oldname);
    return 1;
}

stock StripNewLine(string[])
{
    new len;
    len = strlen(string);
    if(string[0] == 0) return 1;
    if((string[len - 1] == '\n') || (string[len - 1] == '\r'))
    {
        string[len - 1] = 0;
        if(string[0] == 0) return 1;
        if((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
    }
    return 1;
}
Edit: This plugin here also has a 'frename' function.
Reply
#3

Worked 100%, thank you.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)