dracoblue.net

Renaming a file in Pawn

If you are using pawn (for instance in san andreas multiplayer) and want to rename a file, you'll not find a method like frename.

You can either use my

dutils (pawn only solution) or a plugin (like Yless' YSF) to add frename to your functions.

If you want to make a plain pawn solution, and don't want to use dutils, here is how I made it.

There are two steps.

First you'll need fcopy (copies the file):

ohnd=fopen(oldname,io_read);
nhnd=fopen(newname,io_write);
new buf2[1];
new i;
for (i=flength(ohnd);i>0;i--) {
    fputchar(nhnd, fgetchar(ohnd, buf2[0],false),false);
}
fclose(ohnd);
fclose(nhnd);

And then you'll need to remove the old file.

fremove(oldname);

Remember, that on linux those methods will not work (since fputchar is bugged on linux). You need to use the pawnonly frenametextfile and fcopytextfile from

dutils for that.

In pawn by
@ 13 Jun 2009, Comments at Reddit & Hackernews