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
댓글 수: 0
채택된 답변
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!