Codegen supported function to delete a file and to check its existence
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bob Randall
am 4 Jun. 2025
Kommentiert: Walter Roberson
am 5 Jun. 2025
Hello community,
When I run codegen to compile my .m function, I'm getting this error when I use the matlab built-in function delete
??? Function 'delete' is not supported for code generation. Consider adding coder.extrinsic('delete') at the top of the function to bypass code generation.
Error in ==> pathExist Line: 15 Column: 2
Code generation failed: View Error Report
I cannot delcare delete as extrinsic because I need the executable to be stand alone.
Is the a codegen suported function to delete a file and and one check its existence?
I'm using matlab R2018a
Thank you
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 4 Jun. 2025
I believe it would go as follows:
C:
Use
coder.cinclude('<stdio.h>');
coder.ceval('remove', FILENAME);
C++:
Use
coder.cinclude('<cstdio>');
coder.ceval('std::remove', FILENAME);
It would not astonish me if the filename had to be converted to a null-terminated character vector for passing into the function.
To test whether the file exists, C include <sys/stat.h> and call stat() . C++ 17 or later include <filesystem> and call std::filesystem::exists() . For older C++ there are several methods, including include <sys/stat.h> and call stat()
2 Kommentare
Walter Roberson
am 5 Jun. 2025
Generally speaking, the target model for code generation is embedded systems, which might not have any filesystem at all.
That said... code generation does support fopen(), which assumes a file system.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!