Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

FMUArchive is not a directory error #473

@benplay2

Description

@benplay2

Problem

When attempting to create an FMU from a simulink model, I received the following error:

C:\Users\USERID1\AppData\Local\Temp\tpdeb91cc8_6d09_4157_9226_606a8095eb0d\zzzzz_to_be_fmu_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz_fmu_sfcn_rtw_fmi\FMUArchive is not a directory.

This did not happen every time, but I believe occurred after a prior failure.

Solution

I was able to detect where the error occurs and fix it. The issue is that rtwsfcnfmi_make_rtw_hook() uses exist() to check existence of the FMUArchive directory, but does not specify a full path to it. Therefore, it will return that the directory does exist if some folder with that name lives somewhere in your MATLAB path.

This is the reason for MATLAB suggests using isfolder() instead.

Problem:

% remove FMU build directory from previous build
if exist('FMUArchive', 'dir')
   rmdir('FMUArchive', 's'); %This line could be executed even if FMUArchive does not live in the current directory! (which causes an error)
end

Fix:

% remove FMU build directory from previous build
if isfolder('FMUArchive')
    rmdir('FMUArchive', 's');
end

The following logic should be changed where applicable:

  • exist(<something>, 'dir') ➡️ isfolder(<something>)
  • exist(<something>, 'file') ➡️ isfile(<something>)

From a quick search, I found 8 spots that may need this update.
image

System details:

  • Windows 10
  • MATLAB 2022b
  • Compiler: Visual Studio 2017
  • FMIKit version 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions