simulink转移代码

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.");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值