Script to create/load a project

Hello,
I want to write a script to automatically create/load a project in matlab and add relevant folders/files to the project. The following script should be doing it.
clear all;
fullPath = which("loadProj.m");
thisFilePath = "loadProj.m";
project_root = strrep(fullPath, thisFilePath,"");
% Load cuSim project if already the project already exists
projExist = isfile(fullfile(project_root,"\myProj.prj"));
if (projExist)
openProject(project_root);
else
proj = matlab.project.createProject(project_root);
proj.Name = 'MySim';
% Add project root itself
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file1'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file2'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file3'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file4'));
end
However, i get the following error when trying to run the above script multiple times. I have manually deleted the myProj.prj file from the project root but still it gives the following error.
Error using matlab.project.createProject
The specified folder already contains a project.
Error in matlab.project.createProject
Error in matlab.project.createProject
Error in loadSimProj (line 35)
proj = matlab.project.createProject(project_root);

댓글 수: 5

Mario Malic
Mario Malic 2020년 9월 19일
편집: Mario Malic 2020년 9월 19일
The specified folder already contains a project.
I guess one project per folder.
Adnan Khan
Adnan Khan 2020년 9월 19일
Agreed one project per folder, but even after deleting the .proj file from the root directory, the script is supposed to create a new project.
VBBV
VBBV 2020년 9월 19일
Type run command in Windows
Then type %temp% to open the temp folder and delete all the files if present.
Then load the project and See what happens
The issue was resources folder in the project root directory . Removing the folder resolved this issue.
Thanks
clear all;
fullPath = which("loadProj.m");
thisFilePath = "loadProj.m";
project_root = strrep(fullPath, thisFilePath,"");
% Load project if already the project already exists
projExist = isfile(fullfile(project_root,"\myProj.prj"));
if (projExist)
openProject(project_root);
else
status = rmdir(fullfile(project_root,"\resources"),'s');
proj = matlab.project.createProject(project_root);
proj.Name = 'MySim';
% Add project root itself
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file1'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file2'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file3'));
addFolderIncludingChildFiles(MySim, fullfile(project_root,'file4'));
end
Mario Malic
Mario Malic 2020년 9월 20일
편집: Mario Malic 2020년 9월 20일
Then, accept my answer to your question. Thanks in advance.

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

답변 (1개)

Mario Malic
Mario Malic 2020년 9월 19일

0 개 추천

You need to delete .prj file and resources folder with it as well.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

질문:

2020년 9월 19일

편집:

2020년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by