ADDPATH_RECURSE Adds the specified directory and its subfolders addpath_recurse(directory,ignore) Descriptions of Input Variables: directory: full path to the starting directory. All subdirectories will be added to the path as well. If this is not specified, then the current directory will be used. ignore: a cell array of strings specifying directory names to ignore. This will cause all subdirectories beneath this directory to be ignored as well. Descriptions of Output Variables: none Example(s): >> addpath_recurse(pwd,{'.svn'}); %adds the current directory and all subdirectories, ignoring the SVN-generated .svn directories See also: rdir
0001 function addpath_recurse(directory,ignore) 0002 %ADDPATH_RECURSE Adds the specified directory and its subfolders 0003 % addpath_recurse(directory,ignore) 0004 % 0005 % Descriptions of Input Variables: 0006 % directory: full path to the starting directory. All subdirectories 0007 % will be added to the path as well. If this is not specified, then 0008 % the current directory will be used. 0009 % ignore: a cell array of strings specifying directory names to ignore. 0010 % This will cause all subdirectories beneath this directory to be 0011 % ignored as well. 0012 % 0013 % Descriptions of Output Variables: 0014 % none 0015 % 0016 % Example(s): 0017 % >> addpath_recurse(pwd,{'.svn'}); %adds the current directory and all 0018 % subdirectories, ignoring the SVN-generated .svn directories 0019 % 0020 % See also: rdir 0021 0022 % Author: Anthony Kendall 0023 % Contact: anthony [dot] kendall [at] gmail [dot] com 0024 % Created: 2008-08-08 0025 0026 if nargin==0 0027 directory = pwd; 0028 ignore={''}; 0029 elseif nargin==1 0030 ignore={''}; 0031 end 0032 0033 %Add the current directory to the path 0034 assert(exist(directory,'dir')>0,'The input directory does not exist'); 0035 addpath(directory); 0036 0037 %Get list of directories beneath the specified directory 0038 currDir = dir([directory,filesep,'*']); 0039 0040 %Loop through the directory list and recursively call this function 0041 for m = 1:length(currDir) 0042 if ~any(strcmp(currDir(m).name,{'.','..',ignore{:}})) && currDir(m).isdir 0043 addpath_recurse([directory,filesep,currDir(m).name],ignore); 0044 end 0045 end