Interacting with files
Posted: Thu Nov 25, 2021 10:36 pm
I'm trying to add a function to the uos module which should create an empty file on my ESP32.
Something like this:
However, if I run this, I just get "file pointer is null". I'm assuming that I cannot use standard C functions to interact with the filesystem. I probably have to use some other "special" functions, however I could not find any documentation on this.
Does anyone know what functions I have to use to do this? It also would be nice if I could do other operations, like writing data to a file, reading it, delete it, etc.
Something like this:
Code: Select all
STATIC mp_obj_t test() {
mp_int_t ret_val;
printf("attempting to create file \"test.txt\"\n");
FILE* file;
file = fopen("test.txt", "w");
if(file == NULL){
printf("file pointer is null\n");
ret_val = 0;
} else {
printf("file pointer OK\n");
fclose(file);
ret_val = 1;
}
return mp_obj_new_int(ret_val);
}
MP_DEFINE_CONST_FUN_OBJ_0(test_obj, test);
Does anyone know what functions I have to use to do this? It also would be nice if I could do other operations, like writing data to a file, reading it, delete it, etc.