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

조회 수: 5 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2025년 6월 4일
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
Bob Randall
Bob Randall 2025년 6월 4일

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 2025년 6월 5일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by