Skip to content

Commit 05ea7e2

Browse files
committed
speed, compatibility
1 parent 0cb38ae commit 05ea7e2

File tree

7 files changed

+33
-30
lines changed

7 files changed

+33
-30
lines changed

+stdlib/file_size.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
s = [];
1111

12-
d = dir(file);
12+
% char() for Matlab < R2018a
13+
d = dir(char(file));
1314

1415
if isscalar(d) && ~d.isdir
1516
s = d.bytes;

+stdlib/get_modtime.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
t = datetime.empty;
1111

12-
finf = dir(file);
12+
% char() for Matlab < R2018a
13+
finf = dir(char(file));
14+
1315
if ~isempty(finf) && finf.isdir
1416
% find which index of the struct array has member name == '.'
1517
i = find(strcmp({finf.name}, '.'), 1);

+stdlib/handle2filename.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
%% HANDLE2FILENAME Convert a file handle to a filename
1+
%% HANDLE2FILENAME Convert an integer file handle to a filename
2+
%
3+
%%% Inputs
4+
% * fileHandle: Integer file handle as returned by fopen
5+
%%% Outputs
6+
% * n: Filename. Empty if file handle is invalid.
7+
28
function n = handle2filename(fileHandle)
3-
arguments
4-
fileHandle (1,1) {mustBeInteger}
5-
end
69

710
n = '';
811

+stdlib/makedir.m

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33
% This function works around that bug in Matlab mkdir().
44

55
function makedir(direc)
6-
arguments
7-
direc string
8-
end
96

107
%% to avoid confusing making ./~/mydir
11-
for i = numel(direc)
12-
direc(i) = stdlib.expanduser(direc(i));
13-
end
14-
15-
i = ~stdlib.strempty(direc) & ~isfolder(direc);
8+
direc = stdlib.expanduser(direc);
169

17-
for d = direc(i)
18-
[~] = mkdir(d);
10+
if ~stdlib.strempty(direc) && ~isfolder(direc)
11+
[~] = mkdir(direc);
1912
end
2013

21-
ok = isfolder(direc(i));
14+
ok = isfolder(direc);
2215

2316
if nargout == 0
24-
assert(all(ok), "Failed to create directories: %s", strjoin(direc(~ok), ", "));
17+
assert(ok, "Failed to create directory: %s", direc)
2518
end
2619

2720
end

+stdlib/private/fileAttribCompatible.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@
1010
return
1111
end
1212

13-
14-
try
15-
[s, r, id] = fileattrib(file);
16-
catch e
17-
if strcmp(e.identifier, 'MATLAB:string')
18-
[s, r, id] = fileattrib(char(file));
19-
else
20-
rethrow(e)
21-
end
22-
end
13+
% char() for Matlab < R2018a
14+
[s, r, id] = fileattrib(char(file));
2315

2416
end

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The key limitations to minimum Matlab version are:
2121

2222
* R2017b: fileparts() supports string type. fileparts() is used in many places in the code as it's 5-10x faster than regexp() for filename parsing.
2323
* R2018a: fileattrib() supports string type
24+
* R2018a: mfilename('fullpath') tells the full path to the matlab .m file currently running (empty for older Matlab)
2425
* R2019b: function argument validation block "arguments"
2526

2627

test/TestExists.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,24 @@ function test_is_char_device(tc, B_is_char_device)
6666

6767

6868
function Ps = init_val()
69+
70+
6971
Ps = {
7072
{pwd(), true}, ...
71-
{[mfilename("fullpath"), '.m'], true}, ...
72-
{[fileparts(mfilename("fullpath")), '/../Readme.md'], true}, ...
7373
{tempname(), false}, ...
7474
{'', false}
7575
};
76+
77+
o = mfilename('fullpath');
78+
if ~isempty(o)
79+
o = [o, '.m'];
80+
Ps = [Ps, {
81+
{o, true}, ...
82+
{[fileparts(o), '/../Readme.md'], true}
83+
}
84+
];
85+
end
86+
7687
if ispc()
7788
% On Windows, the root of the system drive is considered to exist
7889
systemDrive = getenv("SystemDrive");

0 commit comments

Comments
 (0)