This is a static copy of a profile report

Home

validateFileName (Calls: 2, Time: 0.019 s)
Generated 04-Jun-2021 04:11:06 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\shared\io\general\+matlab\+io\+internal\+validators\validateFileName.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
...eptsReadableFilename.validateFilenameclass method2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
60
validFileNames(hasNoPath) = fu...
20.012 s63.5%
32
[~, ~, ext] = fileparts(filena...
20.004 s18.9%
56
validFileNames = localUnique(v...
20.001 s5.3%
44
isFile = isfile(fileNamesToBeV...
20.000 s2.1%
31
extensions(~startsWith(extensi...
20.000 s2.0%
All other lines  0.002 s8.1%
Totals  0.019 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
fullfilefunction20.011 s58.7%
filepartsfunction40.003 s18.3%
validateFileName>localUniquesubfunction40.001 s4.4%
pwdfunction20.000 s1.0%
Self time (built-ins, overhead, etc.)  0.003 s17.6%
Totals  0.019 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function64
Non-code lines (comments, blank lines)35
Code lines (lines that can run)29
Code lines that did run23
Code lines that did not run6
Coverage (did run/can run)79.31 %
Function listing
time 
Calls 
 line
   1 
function [validFileNames, fileExtensions] = validateFileName(filename, extensions)
   2 
%VALIDATEFILENAME Validate the existence of a specified file.
   3 
%   Validate the existence of a file named FILENAME by searching through
   4 
%   the filesystem. First, check if FILENAME is a valid absolute or
   5 
%   relative path to a file. Otherwise, check for a file named FILENAME on
   6 
%   the MATLAB path.
   7 
%
   8 
%   varargin: Optionally, specify a list of file extensions to search for
   9 
%             as a cell array of character vectors.
  10 
%
  11 
%             For example, if FILENAME == 'myFile' and extensions == {'.txt', '.csv'},
  12 
%             then VALIDATEFILENAME will check for the existence of the following
  13 
%             files, in the order specified below:
  14 
%
  15 
%               1. 'myFile'
  16 
%               2. 'myFile.txt'
  17 
%               3. 'myFile.csv'
  18 
%
  19 
% VALIDATEFILENAME will return all file names matching the specified
  20 
% validation criteria as VALIDFILENAMES, along with their
  21 
% corresponding file extensions as FILEXTENSIONS.
  22 

  23 
%   Copyright 2016-2020 The MathWorks, Inc.
  24 

< 0.001 
      2 
  25
filename = convertCharsToStrings(filename); 
  26 

  27 
% Check if additional file extensions were provided. If so, generate
  28 
% additional file names for validation.
< 0.001 
      2 
  29
if nargin > 1 
< 0.001 
      2 
  30
    extensions = convertCharsToStrings(extensions); 
< 0.001 
      2 
  31
    extensions(~startsWith(extensions,'.')) = "." + extensions(~startsWith(extensions,'.')); 
  0.004 
      2 
  32
    [~, ~, ext] = fileparts(filename); 
< 0.001 
      2 
  33
    if ext == "" 
  34 
        additionalFileNames = filename + extensions;
  35 
        fileNamesToBeValidated = [filename, additionalFileNames];
< 0.001 
      2 
  36
    else 
< 0.001 
      2 
  37
        fileNamesToBeValidated = filename; 
< 0.001 
      2 
  38
    end 
  39 
else
  40 
    fileNamesToBeValidated = filename;
< 0.001 
      2 
  41
end 
  42 

  43 
% Validate file names.
< 0.001 
      2 
  44
isFile = isfile(fileNamesToBeValidated); 
< 0.001 
      2 
  45
validFileNames = fileNamesToBeValidated(isFile); 
< 0.001 
      2 
  46
if any(~isFile,'all') 
  47 
    validFileNames = [validFileNames(:); validateFileNameOnMATLABPath(fileNamesToBeValidated(~isFile))];
< 0.001 
      2 
  48
end 
  49 

  50 
% If no valid files were found, then error.
< 0.001 
      2 
  51
if isempty(validFileNames) 
  52 
    error(message('MATLAB:textio:textio:FileNotFound', filename));
      2 
  53
end 
  54 

  55 

  0.001 
      2 
  56
validFileNames = localUnique(validFileNames); 
  57 
% Get file extensions of valid file names.
< 0.001 
      2 
  58
[paths, ~, fileExtensions] = fileparts(validFileNames); 
< 0.001 
      2 
  59
hasNoPath = (strlength(paths)==0); 
  0.012 
      2 
  60
validFileNames(hasNoPath) = fullfile(pwd,validFileNames(hasNoPath)); 
  61 
% Return only unique file names and extensions.
< 0.001 
      2 
  62
fileExtensions = cellstr(localUnique(fileExtensions)); 
< 0.001 
      2 
  63
validFileNames = cellstr(validFileNames); 
< 0.001 
      2 
  64
end 

Other subfunctions in this file are not included in this listing.