Remove the slprj folder programmatically
이전 댓글 표시
There is an 'slprj' in the working directory that is from another Simulink version. Consequently, I receive the error
'The existing Simulink code generation folder in the current folder was created for a different version of MathWorks products. This project folder is not compatible with the current version. To continue you must manually remove the slprj folder and any generated code files it contains.'
when trying to compile my model. However, I do not want to manually remove the folder each time. The programmatic approach via
rmdir('slprj')
from the MATLAB command line also issues an error.
So how can I programmatically remove the 'slprj' folder?
댓글 수: 9
Jan
2018년 11월 21일
If you mention, that an error occurs, be so kind to post the error message also. It is easier to fix an error than to guess, what the error is.
Bonpland
2018년 11월 21일
Jan
2018년 11월 21일
The directory migt be in use, e.g. when a contained file is open. Is 'slprj' a folder inside the current directory? Using absolute path names is more secure than relying on the current directory.
Image Analyst
2018년 11월 21일
What does this do:
folder = 'slprj'
if exist(folder, 'dir')
rmdir(folder)
else
message = sprintf('The folder %s does not exist', folder)
uiwait(errordlg(message));
end
Bonpland
2018년 11월 21일
Image Analyst
2018년 11월 21일
So it is a existing subfolder of your current folder but it won't let you delete it. The only reason I can think of is you don't have permission, either because the folder was being viewed in File Explorer, or you have a file from it open in some program, or the folder is readonly, or similar.
Can you delete it manually in WIndows Explorer (Windows 7), File Explorer (Windows 10), or Finder (mac)?
Bonpland
2018년 11월 21일
Mostaza Con huevos
2021년 2월 12일
someone else can helpme whit the folder slprj all the folder.
답변 (3개)
Sean de Wolski
2018년 11월 21일
What about with the 's' option
rmdir('slprj', 's')
댓글 수: 2
Gordon Lai
2020년 4월 2일
The full path version of this worked for me as 'slprj' is not empty (nor is it usually).
Note: I first added it and subfolders to the MATLAB path, using
addpath(genpath(pwd))
(unsure if that is necessary)
Sean de Wolski
2020년 4월 2일
편집: Sean de Wolski
2020년 4월 2일
Typically if you're calling addpath/genpath, you should be using a project. This also lets you customize code generation settings at a project level.
This does not solve the problem, but helps to identify the problem: Catch the error message:
[status, msg] = rmdir('slprj')
if status ~= 1
fprintf(2, '%s\n', msg);
end
By the way, of course you can use absolute path names even on different platforms. This does not mean a hard coded path name, but that you do not rely on the current directory to be, what you expect. Remember that each timer and GUI callback can use cd to change the current directory, and rmdir('slprj') might access an unexpected folder. Better:
baseFolder = cd; % Or even better: define it with a meaningful folder
[status, msg] = rmdir(fullfile(baseFolder, 'slprj'))
if status ~= 1
fprintf(2, 'Folder: %s\nProblem: %s\n', ...
fullfile(baseFolder, 'slprj'), msg);
end
Now the error message should be more useful.
댓글 수: 4
@Bonpland: This sounds strange, because then the replied status must be 1, which means a successful deleting. In case of a problem, the error message written by my code would contain the name of the folder.
Even empty folders can require different privileges for deleting, so it does not matter if the subfolders are empty.
Do you have any evidence, that the current directory is what you expect it to be? Is the folder really empty, when you call rmdir or did you test this some seconds later only in the Windows Explorer - with enabled display of hidden and system files? Remember that e.g. the virus scanner might access and block the files, so what happens with a fallback method:
ready = false;
count = 0;
folder = fullfile(baseFolder, 'slprj');
while count < 10 && ~ready
count = count + 1;
[status, msg] = rmdir(folder);
if status == 1
ready = true;
else
fprintf(2, 'Folder: %s\nProblem: %s\n...retrying...\n', ...
folder, msg);
pause(0.5);
end
end
if count == 10
fprintf(2, 'Deleting folder failed: %s\n', folder);
end
There is still a detail you did not mention, because you are not aware of it. So please post as much details as you can to give the readers a chance to see, what you do not see.
Jan
2018년 11월 29일
The next question: What does "There is an 'slprj' in the working directory that is from another Simulink version" mean? Is "the other Simulink version" still running?
Bonpland
2018년 11월 29일
0 개 추천
댓글 수: 1
Jan
2018년 11월 29일
Please do not post a pseudo-answer only to bump your question. This wastes the time of all readers. This is the public forum. If you want MathWorks to react to your question, contact them directly using the "Contact Us" link on top of this page.
카테고리
도움말 센터 및 File Exchange에서 Using MATLAB Projects in Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!