Skip to content

Commit

Permalink
Update osp_saveLCM.m
Browse files Browse the repository at this point in the history
Changes to correctly split a path even if that path was created on a
different system (with a different 'filesep' placeholder)
  • Loading branch information
schorschinho committed Apr 15, 2024
1 parent 24082d5 commit 8527cb4
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions process/osp_saveLCM.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

% For batch analysis, get the last two sub-folders (e.g. site and
% subject) to augment the filename, avoiding duplicate output filenames
path_split = regexp(path,filesep,'split');
path_split = splitPath(path);
if length(path_split) > 2
name = [path_split{end-1} '_' path_split{end} '_' filename];
end
Expand Down Expand Up @@ -127,7 +127,7 @@

% For batch analysis, get the last two sub-folders (e.g. site and
% subject) to augment the filename, avoiding duplicate output filenames
path_ref_split = regexp(path_ref,filesep,'split');
path_ref_split = splitPath(path_ref);
if length(path_ref_split) > 2
name_ref = [path_ref_split{end-1} '_' path_ref_split{end} '_' filename_ref];
end
Expand All @@ -154,7 +154,7 @@

% For batch analysis, get the last two sub-folders (e.g. site and
% subject) to augment the filename, avoiding duplicate output filenames
path_w_split = regexp(path_w,filesep,'split');
path_w_split = splitPath(path_w);
if length(path_w_split) > 2
name_w = [path_w_split{end-1} '_' path_w_split{end} '_' filename_w];
end
Expand All @@ -171,4 +171,33 @@
% Set exit flags
MRSCont.flags.didLCMWrite = 1;

end

function path_split = splitPath(pathIn)
% This function correctly splits a path even if that path was created on a
% different system (e.g., I'm trying to open an MRSCont that was generated
% on Mac on a Windows machine - in that case, the path will not get split
% at all because the filesep placeholder on the Windows machine does not
% catch the (different) file separators in the Mac-generated path

% Is the current filesep placeholder in the path at all?
isFileSepInPath = contains(pathIn, filesep);

if isFileSepInPath
% the filesep placeholder is in the path, proceed as usual
path_split = regexp(pathIn, filesep, 'split');
else
% the filesep placeholder is NOT in the path - choose the respective
% other
if strcmp(filesep, '/')
filesepNew = '\';
elseif strcmp(filesep, '\')
filesepNew = '/';
else
error('Unknown filesep');
end
% Split path with the updated filesep
path_split = regexp(pathIn, filesepNew, 'split');
end

end

0 comments on commit 8527cb4

Please sign in to comment.