Home > mrg > MRG_utilities > mrg_oswalk.m

mrg_oswalk

PURPOSE ^

Walks a directory and returns a cell array of file names

SYNOPSIS ^

function fileList = mrg_oswalk(dirName)

DESCRIPTION ^

 Walks a directory and returns a cell array of file names
 
 INPUT
   dirName   A string. The directory to walk.  

 OUTPUT
   fileList  DESCRIPTION

 NOTES
   Additional (more verbose) documentation can go here.

 REFERENCES
 Originally from:
  http://stackoverflow.com/questions/2652630/how-to-get-all-files-under-a-specific-directory-in-matlab

 AUTHORS
   Daniel Pritchard

 LICENCE
   Code distributed as part of the MRG toolbox from the Marine Research
   Group at Queens Univeristy Belfast (QUB) School of Planning
   Architecture and Civil Engineering (SPACE). Distributed under a
   creative commons CC BY-SA licence, retaining full copyright of the
   original authors.

   http://creativecommons.org/licenses/by-sa/3.0/
   http://www.qub.ac.uk/space/
   http://www.qub.ac.uk/research-centres/eerc/

 DEVELOPMENT
   v 1.0   2013-09-16
           First version. DP
% Function Begin!

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fileList = mrg_oswalk(dirName)
0002 % Walks a directory and returns a cell array of file names
0003 %
0004 % INPUT
0005 %   dirName   A string. The directory to walk.
0006 %
0007 % OUTPUT
0008 %   fileList  DESCRIPTION
0009 %
0010 % NOTES
0011 %   Additional (more verbose) documentation can go here.
0012 %
0013 % REFERENCES
0014 % Originally from:
0015 %  http://stackoverflow.com/questions/2652630/how-to-get-all-files-under-a-specific-directory-in-matlab
0016 %
0017 % AUTHORS
0018 %   Daniel Pritchard
0019 %
0020 % LICENCE
0021 %   Code distributed as part of the MRG toolbox from the Marine Research
0022 %   Group at Queens Univeristy Belfast (QUB) School of Planning
0023 %   Architecture and Civil Engineering (SPACE). Distributed under a
0024 %   creative commons CC BY-SA licence, retaining full copyright of the
0025 %   original authors.
0026 %
0027 %   http://creativecommons.org/licenses/by-sa/3.0/
0028 %   http://www.qub.ac.uk/space/
0029 %   http://www.qub.ac.uk/research-centres/eerc/
0030 %
0031 % DEVELOPMENT
0032 %   v 1.0   2013-09-16
0033 %           First version. DP
0034 %% Function Begin!
0035 dirData = dir(dirName);      % Get the data for the current directory
0036 dirIndex = [dirData.isdir];  % Find the index for directories
0037 fileList = {dirData(~dirIndex).name}';  % Get a list of the files
0038 if ~isempty(fileList)
0039     fileList = cellfun(@(x) fullfile(dirName,x),...  % Prepend path to files
0040         fileList,'UniformOutput',false);
0041 end
0042 subDirs = {dirData(dirIndex).name};  % Get a list of the subdirectories
0043 validIndex = ~ismember(subDirs,{'.','..'});  % Find index of subdirectories that are not '.' or '..'
0044 for iDir = find(validIndex)                  % Loop over valid subdirectories
0045     nextDir = fullfile(dirName,subDirs{iDir});    % Get the subdirectory path
0046     fileList = [fileList; getAllFiles(nextDir)];  % Recursively call getAllFiles
0047 end
0048 end

Generated on Thu 29-May-2014 21:29:53 by m2html © 2005