||
clc
clear
dir_name=genpath(pwd);
grep(dir_name,'.L_ext','*.m')
----------------------------------------------------------------------------------
function grep(dir_name,pattern, filetype)
dirs=regexp(dir_name,';','split');
[~,wide]=size(dirs);
for i=1:wide
%disp(dirs{1,i});
file=dir ([dirs{1,i},'\',filetype]);
if size(file,1)>0
for j=1:size(file,1)
grep0([dirs{1,i},'\',file(j).name], pattern)%file(j).folder
end
end
end
end
-----------------------------------------------------------------------------------
function grep0(fname, pattern)
fid=fopen(fname,'r');
line_n=0;
while feof(fid)==0
line = fgetl(fid);
if length(class(line))==4 && any(class(line)=='char') && contains(line,pattern)
disp(['at:',fname,' lines:',num2str(line_n+1),'->',line])
%fprintf(['%d:%s\n',line_n+1,line])
end
line_n=line_n+1;
end
fclose(fid);
end
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-25 12:22
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社