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

2 ビュー (過去 30 日間)
Bob Randall
Bob Randall 2025 年 6 月 4 日
コメント済み: Walter Roberson 2025 年 6 月 5 日
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