Targetfile='CODE';
MainPath=pwd;
rtwPath="TBD";
slprjPath="TBD";
TargetfileExist=0;
%search for target folder
MainfileList=dir(MainPath);
for i=3:length(MainfileList)
if rtwPath~="TBD"&&slprjPath~="TBD"&&TargetfileExist
break;
end
if contains(MainfileList(i).name,'_autosar_rtw')&&MainfileList(i).isdir
rtwPath=[MainPath,'\',MainfileList(i).name];
continue;
end
if contains(MainfileList(i).name,'slprj')&&MainfileList(i).isdir
slprjPath=[MainPath,'\slprj'];
continue;
end
if contains(MainfileList(i).name,Targetfile)&&MainfileList(i).isdir
TargetfileExist=1;
continue;
end
end
clearvars MainfileList;
if rtwPath=="TBD"&&slprjPath=="TBD"
disp("No code folder exists, please generate code.");
clear;
return;
end
if TargetfileExist
rmdir(Targetfile,'s');
end
clearvars TargetfileExist;
TargetPath=[MainPath,'\',Targetfile];
mkdir (TargetPath);
clearvars Targetfile MainPath;
%collect .c and .h in rtw folder
if rtwPath~="TBD"
rtwfileList=dir(rtwPath);
for i=3:length(rtwfileList)
rtwCFile=strfind(rtwfileList(i).name,'.c');
rtwHFile=strfind(rtwfileList(i).name,'.h');
if (~isempty(rtwCFile)) || (~isempty(rtwHFile))
copyfile([rtwPath,'\',rtwfileList(i).name],TargetPath,'f');
end
end
rmdir(rtwPath,'s');
end
clearvars rtwPath rtwfileList rtwCFile rtwHFile;
%collect .c and .h in slprj folder
if slprjPath~="TBD"
slprjfileList=dir([slprjPath,'\autosar\_sharedutils']);
for i=3:length(slprjfileList)
slprjCFile=strfind(slprjfileList(i).name,'.c');
slprjHFile=strfind(slprjfileList(i).name,'.h');
slprjM1EFile=strfind(slprjfileList(i).name,'M1E_AppVersion');%M1E no need this file
if (~isempty(slprjCFile)) || ((~isempty(slprjHFile) && isempty(slprjM1EFile)))
copyfile([slprjPath,'\autosar\_sharedutils\',slprjfileList(i).name],TargetPath,'f');
end
end
rmdir(slprjPath,'s');
end
clearvars slprjPath slprjfileList slprjCFile slprjHFile TargetPath i;
disp("Done.");
simulink转移代码
于 2023-11-17 08:47:24 首次发布