SA-MP Forums Archive
Write file with specified name - 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: Write file with specified name (/showthread.php?tid=388858)



Write file with specified name - nickbouwhuis - 30.10.2012

Hello guys.

This is going to be easy.

I want to create a command that makes an empty file with my filename.

For example: /file lemon writes a file called lemon.txt in scriptfiles.

How can I do that? I just started with scripting, and want to know how I can do this. It would also help others that are just starting out!

Thanks!

And as always, have nice day!


Re: Write file with specified name - Bakr - 30.10.2012

There is no CreateFile function unfortunately. However, you can simply open the file in io_write mode and instantly close it, which will create the file.

pawn Код:
CMD:file(playerid, params[]) {

    if(isnull(params) || !strfind(params, ".")) {
        // invalid file format or no params entered
        // this is a VERY shitty way of checking, so
        // I highly suggest expanding this check to
        // include already existed file names,
        // spaces, invalid characters, etc.
    } else {
        new File: hFile = fopen(params, io_write);
        fclose(hFile);
    }
    return 1;
}
As explained in the code, the file check is VERY basic. Expand on it in case of improper input.