-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetFilesInFolder.m
42 lines (36 loc) · 1.12 KB
/
GetFilesInFolder.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
function fileList = GetFilesInFolder (folderPath, fileExtension)
% 2023/03/03
if ~iscell (fileExtension)
fileList = dir(fullfile(folderPath, fileExtension));
else
fileList = struct([]);
for i = 1:numel(fileExtension)
fileListTemp = dir(fullfile(folderPath, fileExtension{i}));
if ~isempty (fileListTemp)
fileList = [fileList; fileListTemp];
end
clear fileListTemp
end
end
if isempty (fileList)
fileList = [];
return
end
% Rename and delete some fields of the file lists.
[fileList.fileName] = fileList.name;
fileList = orderfields(fileList,[1:0,7,1:6]);
fileList = rmfield(fileList,'name');
[fileList.folderPath] = fileList.folder;
fileList = orderfields(fileList,[1:1,7,2:6]);
fileList = rmfield(fileList,'folder');
fileList = rmfield(fileList, 'isdir');
fileList = rmfield(fileList, 'datenum');
% Add the entire filepath to the filelists.
for i = 1:length (fileList)
% Construct path to filename.
fileList(i).filePath = [fileList(i).folderPath,...
'\', fileList(i).fileName];
end
% Reorder some fields.
fileList = orderfields(fileList, [1:2,5,3:4]);
end