Skip to content

Commit 76ac5b0

Browse files
committed
exists: compatibility but keep speed
1 parent 3288e25 commit 76ac5b0

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

+stdlib/exists.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212
function y = exists(fpath)
1313

14-
y = isfile(fpath) || isfolder(fpath);
14+
try
15+
y = isfile(fpath) || isfolder(fpath);
16+
catch e
17+
if strcmp(e.identifier, 'MATLAB:UndefinedFunction')
18+
y = exist(fpath,'file') == 2 || exist(fpath, 'dir') == 7;
19+
else
20+
rethrow(e)
21+
end
22+
end
1523

1624
end
1725

test/TestFilePure.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2017b', 'pure'}) ...
2+
TestTags = {'R2017a', 'pure'}) ...
33
TestFilePure < matlab.unittest.TestCase
44

55

test/TestFilename.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2017b', 'pure'}) ...
2+
TestTags = {'R2017a', 'pure'}) ...
33
TestFilename < matlab.unittest.TestCase
44

55
properties (TestParameter)

test/TestIsExe.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'R2017b', 'pure'}) ...
2+
TestTags = {'R2017a', 'pure'}) ...
33
TestIsExe < matlab.unittest.TestCase
44

55
properties (TestParameter)

test/TestWhich.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010

11-
methods (Test, TestTags = {'R2017b'})
11+
methods (Test, TestTags = {'R2017a'})
1212

1313
function test_which_name(tc)
1414

0 commit comments

Comments
 (0)