forked from ilkkavir/EFISR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listhdf5files.m~
55 lines (50 loc) · 1.4 KB
/
listhdf5files.m~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function [flist] = listhdf5files( varargin )
%
% given an arbitrary number of directories, concatenate the output
% structs of dir('*.hdf5'). The "names" fields are modified to
% contain full absolute paths to the files
%
% INPUT:
% directory paths as strings
%
% OUTPUT:
% flist a matlab struc similar to output of dir, but with absolute
% paths and outputs of all input directories concatenated.
%
% IV 2016
%
nd = length(varargin);
flist = [];
if nd > 0
for dd = 1:nd
ddpath = strtrim(varargin{dd});
% is this an absolute path?
if ddpath(1) ~= filesep
% no, make it absolute
ddpath = fullfile(pwd,ddpath);
end
tmplist = [];
% is this a directory?
if isdir(ddpath)
% list mat files
tmplist = dir(fullfile(ddpath,'*.hdf5'));
% convert into full paths
ntmp = length(tmplist);
for ff=1:ntmp
tmplist(ff).name = fullfile(ddpath,tmplist(ff).name);
end
% is this a mat-file?
elseif exist(ddpath,'file')
if ddpath(end-4:end) == '.hdf5'
tmplist = dir(ddpath);
tmplist.name = ddpath;
end
end
% concatenate all directory listings.
flist = [flist;tmplist];
end
end
% remove possible duplicates
[ii,ii]=unique({flist.name},'stable');
flist=flist(ii);
end