31.05.2014, 04:54
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.
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;
}