Lists all the file names in a directory. Usage: filenames = SurfStatListDir( dir [, exclude] ); d = directory, including wildcards such as '*'. exclude = matrix with rows as strings; any file name containing any of these strings will be excluded. Empty by default. filenames = structure array of file names. e.g. SurfStatListDir('c:/somedir/someplace/subject*_thickness.txt');
0001 function filenames = SurfStatListDir( d, exclude ); 0002 0003 %Lists all the file names in a directory. 0004 % 0005 % Usage: filenames = SurfStatListDir( dir [, exclude] ); 0006 % 0007 % d = directory, including wildcards such as '*'. 0008 % exclude = matrix with rows as strings; any file name containing 0009 % any of these strings will be excluded. Empty by default. 0010 % 0011 % filenames = structure array of file names. 0012 % 0013 % e.g. SurfStatListDir('c:/somedir/someplace/subject*_thickness.txt'); 0014 0015 if nargin<2 0016 exclude=[]; 0017 end 0018 path=fileparts(d); 0019 f=dir(d); 0020 j=0; 0021 for i=1:length(f); 0022 if ~f(i).isdir 0023 y=1; 0024 for k=1:size(exclude,1) 0025 y=y&isempty(strfind(f(i).name,exclude(k,:))); 0026 end 0027 if y 0028 j=j+1; 0029 filenames{j,1}=fullfile(path,f(i).name); 0030 end 0031 end 0032 end 0033 fprintf(1,'%s\n',['List ', num2str(j) ' file names, first one is:']); 0034 fprintf(1,'%s\n',filenames{1}); 0035 0036 return 0037 end