To create a new file

From ThaiEasyElecWiki
Jump to: navigation, search

To create a new file, simply use function sd_open_write or sd_open_write2 with mode 'W' (Write).

int sd_open_write(char mode, char *wr_file)
int sd_open_write2(char mode, char *wr_path)

The difference between these 2 functions is that "wr_file" is used when the target file is in the current directory, while "wr_path" is used wherever the current directory is as it locates the full path of the target file from root. For example, if the target file is in folder "config", then it's full path is "config/config.txt".

After using sd_open_write or sd_open_write2, no file is created, you have to write something on the file by using sd_write or sd_write2.

int sd_write(int len, char *data)
int sd_write2(char *data)

Note that sd_write2 doesn't need "len" (length of data to be written) as it will see data as a text and stop writing when 0 (0x00) is found. So sd_write should be used with binary data that may contain 0 while sd_write2 should be used with texts.

Next time when you're going to append the existing file, use sd_open_write or sd_open_write2 with mode 'A' (Append).

Personal tools
Namespaces
Variants
Actions
Navigation
Articles and Tutorials
Shortcut (mini SUN7)
Toolbox