-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbst_fileparts.m
61 lines (58 loc) · 2.07 KB
/
bst_fileparts.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
56
57
58
59
60
function varargout = bst_fileparts(filename, isFolder)
% BST_FILEPARTS: Same as Matlab's fileparts, but consider '\' as file separators on Linux/MacOS systems.
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c)2000-2020 University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2010
% Parse inputs
if (nargin < 2) || isempty(isFolder)
isFolder = 0;
end
% Empty input
if isempty(filename)
filename = '';
end
% MacOS and Linux: Replace \ with /
if ~ispc
filename(filename == '\') = '/';
end
% Check if link
if (length(filename) > 5) && strcmpi(filename(1:5), 'link|')
if (nargout >= 1)
varargout{1} = 'link';
end
if (nargout >= 2)
varargout{2} = filename;
end
if (nargout >= 3)
varargout{3} = [];
end
% Folder: split only with str_split
elseif isFolder
% Replace dots with invalid characters, to avoid splitting the folder names that include dots
filename = strrep(filename, '.', '>');
% Split filename
[varargout{1:nargout}] = fileparts(filename);
% Restore the dots
for i = 1:length(varargout)
varargout{i} = strrep(varargout{i}, '>', '.');
end
% Regular file
else
[varargout{1:nargout}] = fileparts(filename);
end