Codegen supported function to delete a file and to check its existence

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Juin 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 commentaires
Bob Randall
Bob Randall le 4 Juin 2025

So I need to use external function calls to the c or c++ standard libs. It will definitely work. I wish codegen was a little bit more advanced. Thank you Walter

Walter Roberson
Walter Roberson le 5 Juin 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by