Home > atmlab > files > whichfiles.m

whichfiles

PURPOSE ^

WHICHFILES Gives a list of files in a folder

SYNOPSIS ^

function filenames = whichfiles( rgexp, folder )

DESCRIPTION ^

 WHICHFILES   Gives a list of files in a folder

    The function returns all files in a folder that match some regular
    search expression. 

    Folders are ignored. This means that '*' will not include . and ..

 FORMAT   filenames = whichfiles( [ rgexp, folder ] )
        
 OUT   filenames   Cell array of strings with names of files. Complete path
                   is given.
 OPT   rgexp       Search expression, such as '*.mat'. Default is '*'.
       folder      Path to folder. If not given, pwd is used.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

whichfiles.m

SOURCE CODE ^

0001 % WHICHFILES   Gives a list of files in a folder
0002 %
0003 %    The function returns all files in a folder that match some regular
0004 %    search expression.
0005 %
0006 %    Folders are ignored. This means that '*' will not include . and ..
0007 %
0008 % FORMAT   filenames = whichfiles( [ rgexp, folder ] )
0009 %
0010 % OUT   filenames   Cell array of strings with names of files. Complete path
0011 %                   is given.
0012 % OPT   rgexp       Search expression, such as '*.mat'. Default is '*'.
0013 %       folder      Path to folder. If not given, pwd is used.
0014 
0015 % 2006-02-01   Created by Patrick Eriksson.
0016 
0017 
0018 function filenames = whichfiles( rgexp, folder )
0019 
0020 
0021 if nargin < 1
0022   rgexp = '*';
0023 end
0024 if nargin < 2
0025   folder = pwd;
0026 end
0027 
0028 
0029 %= Search folder
0030 %
0031 D = dir( fullfile( folder, rgexp ) );
0032 
0033 
0034 %= Create filenames
0035 %
0036 filenames = [];  % If no files found
0037 %
0038 if ~isempty(D)
0039   j = 0;
0040   for i = 1:length(D)
0041     if ~D(i).isdir
0042       j = j + 1;
0043       filenames{j} = fullfile( folder, D(i).name );
0044     end
0045   end
0046 end
0047

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005