getfilelist.m

来自「获取指定文件夹下的所有文件的例表」· M 代码 · 共 51 行

M
51
字号
function filelst = getfilelist(pathn, ext)
% GETFILELIST   Get the file list of the given path and ext. For internal use.
%
% filelst = getfilelist(pathn, ext)
%    pathn  path name
%    ext    extended name of the file
%
%   Return value:
%   filelst     the file list (cell)
%
%   Copyright 2002 
%   Bi Xiangjun, Dalian University of Technology ( DUT )
%   $Revision: 1.5 $  $Date: 2005/04/30 $
%   If no file was found, filelst = [] is considered in version 1.5.A: Qu.

tmp = dir(pathn);
[m,n]=size(tmp);
if (exist('ext')~=1)
    ext='';
end
if (isempty(ext))
   tmpext = '';
elseif (ext(1) ~= '.')
   tmpext=strcat('.',ext);
else
   tmpext=ext;
end
[x,t]=size(tmpext);
if(t~=0) 
   tmpext=tmpext(1,t:-1:1);
end

n=0;   
for i=1:m
   if (~tmp(i).isdir)
      [x,t]=size(tmp(i).name);
      x = findstr(tmp(i).name(1,t:-1:1), tmpext);
      if (isempty(x)) 
         x=0;
      end
      
      if (isempty(ext)|x==1)
         n=n+1;
         filelst{n}=tmp(i).name;
      end
   end
end
if n == 0
    filelst = [];
end
   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?