SYS.IS_REMOVABLE
function y = is_removable(filepath)
y = false;
if ispc()
r = stdlib.root_name(filepath);
if stdlib.strempty(r)
return
end
r = extractBefore(r, 2);
psFile = [fileparts(mfilename('fullpath')), '/isRemovableDrive.ps1'];
mustBeFile(psFile)
psCmd = sprintf('. ''%s''; IsRemovableDrive -DriveLetter ''%s''', psFile, r);
cmd = sprintf('powershell -ExecutionPolicy Bypass -Command "& {%s}"', psCmd);
else
cmd = sprintf('df "%s" | tail -n 1 | awk ''{print $1}''', filepath);
end
[s1, m1] = system(cmd);
if s1 ~= 0
warning('stdlib:is_removable:OSError', '%s', m1)
return
end
if ispc()
y = contains(m1, "True");
elseif ismac()
cmd2 = sprintf('diskutil info "%s"', deblank(m1));
[s2, m2] = system(cmd2);
y = s2 == 0 && ~isempty(regexp(m2, "Removable Media:\s*(Removable)", 'once'));
else
dev = deblank(extractAfter(m1, '/dev/'));
f1 = sprintf('/sys/class/block/%s/removable', dev);
try
d = fileread(f1);
y = d(1) == '1';
catch e
if ~strcmp(e.identifier, 'MATLAB:fileread:cannotOpenFile')
rethrow(e)
end
end
end
end