-
Notifications
You must be signed in to change notification settings - Fork 0
/
osPathSwitch.m
46 lines (39 loc) · 1.23 KB
/
osPathSwitch.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
function outputPath = osPathSwitch(input,options)
arguments
input % string or char
options.inputOS string = 'auto'
end
switchOS = false;
server_mac = '/Volumes/MICROSCOPE/';
server_win = '\\research.files.med.harvard.edu\neurobio\MICROSCOPE\';
% Determine operation system
if ispc; targetOS = 'win';
elseif isunix; targetOS = 'mac';
end
% Detect input OS if needed
if strcmp(options.inputOS,'auto')
if contains(input,'\') || contains(input,'research.files.med.harvard.edu')
options.inputOS = 'win';
elseif contains(input,'/') || contains(input,'Volumes')
options.inputOS = 'mac';
end
end
% Determine whether to swtich or not
if strcmp(options.inputOS,targetOS)
outputPath = input;
return
else
switchOS = true;
end
% Detect and replace server path
if contains(input,server_mac) && switchOS % change from mac to windows
splitted = strsplit(input,server_mac);
outputPath = [server_win,splitted{2}];
outputPath(strfind(outputPath,'/')) = '\';
elseif contains(input,server_win) && switchOS % change from windows to mac
input(strfind(input,'\')) = '/';
server_win(strfind(server_win,'\')) = '/';
splitted = strsplit(input,server_win);
outputPath = [server_mac,splitted{2}];
end
end