www.gusucode.com > datastoreio工具箱 matlab源码程序 > datastoreio/+matlab/+io/+datastore/+internal/pathLookup.m
function [f, s] = pathLookup(pths, includeSubfolders, noSuggestionInErr) %PATHLOOKUP Get resolved file names and file sizes for input paths. % FILES = pathLookup(PATHS) returns the fully resolved file names for the % paths or IRIs specified in PATHS. This happens non-recursively by % default i.e. we do not look under subfolders while resolving. PATHS can % be a single string or a cell array of strings denoting paths to files % or folders. The path can include wildcards. % % FILES = pathLookup(PATHS, INCLUDESUBFOLDERS) returns the fully resolved % file names for the paths or IRIs specified in PATHS taking % INCLUDESUBFOLDERS into account. % 1) If a path refers to a single file, that file is added to the output. % 2) If a path refers to a folder % i) all files in the specified folder are added to the output. % ii) if INCLUDESUBFOLDERS is false, subfolders are ignored. % iii) if INCLUDESUBFOLDERS is true, all files in all subfolders are % added. % 3) If path refers to a wild card: % i) all files matching the pattern are added. % ii) if INCLUDESUBFOLDERS is false, folders that match the pattern % are looked up just for files. % iii) if INCLUDESUBFOLDERS is true, an error is thrown. % % FILES = pathLookup(PATHS, INCLUDESUBFOLDERS, NOSUGGESTIONINERR) errors % with the suggestion to use pathLookup with IncludeSubfolders if % NOSUGGESTIONINERR is false (default). % % [FILES,FILESIZES] = pathLookup(PATHS) also returns the file sizes for % the resolved paths as an array of double values. % % For more information on IRIs, please refer to % http://en.wikipedia.org/wiki/Internationalized_resource_identifier % % Copyright 2014-2016, The MathWorks, Inc. narginchk(1,3); nargoutchk(0,2); % imports import matlab.io.datastore.internal.isIRI; import matlab.io.datastore.internal.pathLookupNative; import matlab.io.datastore.internal.pathLookupLocal; import matlab.io.datastore.internal.validators.isNumLogical; import matlab.io.datastore.internal.validators.validatePaths; % returns {} for {} pths = validatePaths(pths); % empty case if nargout > 0 f = {}; s = []; end if isempty(pths) return; end % validate recursive lookup option. switch nargin case 1 includeSubfolders = false; noSuggestionInErr = false; case 2 noSuggestionInErr = false; % do not break, so we check next case {2,3} case {2, 3} % Check if the given includeSubfolders option is logical or not if ~isNumLogical(includeSubfolders) error(message('MATLAB:datastoreio:pathlookup:invalidIncludeSubfolders')); end includeSubfolders = logical(includeSubfolders); end % call to underlying builtin which does the actual lookup switch nargout case 0 pathLookupNative(pths, includeSubfolders); case 1 for ii = 1:length(pths) pth = pths{ii}; try if isIRI(pth) f = [f; pathLookupNative(pth, includeSubfolders)]; continue; end f = [f; pathLookupLocal(pth, includeSubfolders)]; catch e iHandleEmptyFolderError(e, pth, noSuggestionInErr); end end case 2 for ii = 1:length(pths) pth = pths{ii}; try if isIRI(pth) [fCurr, sCurr] = pathLookupNative(pth, includeSubfolders); f = [f; fCurr]; s = [s; sCurr]; continue; end [fCurr, sCurr] = pathLookupLocal(pth, includeSubfolders); catch e iHandleEmptyFolderError(e, pth, noSuggestionInErr); end f = [f; fCurr]; s = [s; sCurr]; end end end function iHandleEmptyFolderError(e, pth, noSuggestionInErr) % Throw emptyFolderNoSuggestion error message if noSuggestionInErr is true % which does not have a suggestion to use IncludeSubfolders. % This is required for datastores when they do not support IncludeSubfolders, % for example, in TallDatastore. if noSuggestionInErr && strcmp(e.identifier, 'MATLAB:datastoreio:pathlookup:emptyFolder') error(message('MATLAB:datastoreio:pathlookup:emptyFolderNoSuggestion', pth)); end throw(e); end