From 57faed78c0acb20aeedecdbeb3703b4caf79eedb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Tue, 10 Oct 2017 13:19:07 +0200
Subject: [PATCH] Generalised isfile routine (to accept more than one file name
 to be tested).

(cherry picked from commit a83258d4aff1b7d40499c1203a39774970ab6ee1)
---
 matlab/utilities/general/isfile.m | 49 ++++++++++++++++++++++++-------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/matlab/utilities/general/isfile.m b/matlab/utilities/general/isfile.m
index 59f118710..ece12f43f 100644
--- a/matlab/utilities/general/isfile.m
+++ b/matlab/utilities/general/isfile.m
@@ -27,7 +27,7 @@ function a = isfile(b)
 %! @end deftypefn
 %@eod:
 
-% Copyright (C) 2012 Dynare Team
+% Copyright (C) 2012-2017 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -44,18 +44,45 @@ function a = isfile(b)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
+stringarrayflag = false;
+cellofstringflag = false;
+n = 1;
+a = false;
 
-[base,ext] = strtok(b,'.');
+if isstring(b) && length(b)>1 && isvector(b)
+    n = length(b);
+    stringarrayflag = true;
+    a = false(size(b));
+end
 
-if isempty(ext)
-    % File has no extension.
-    [status, c] = fileattrib(b);
-    if status
-        a = ~c.directory;
+if iscell(b) && length(b)>1 && isvector(b)
+    if all(cellfun(@ischar, b))
+        n = length(b);
+        cellofstringflag = true;
+        a = false(size(b));
     else
-        a = 0;
+        error('Wrong input argument type!')
+    end
+end
+
+for i=1:n
+    if stringarrayflag
+        d = b(i);
+    elseif cellofstringflag
+        d = b{i};
+    elseif ischar(b) && size(b, 1)==1 
+        d = b;
+    else
+        error('Wrong input argument type!')
+    end
+    [base, ext] = strtok(d, '.');
+    if isempty(ext)
+        % File has no extension.
+        [status, c] = fileattrib(d);
+        if status
+            a(i) = ~c.directory;
+        end
+    else
+        a(i) = isequal(exist(d, 'file'), 2);
     end
-else
-    a = isequal(exist(b,'file'),2);
 end
\ No newline at end of file
-- 
GitLab