-
Notifications
You must be signed in to change notification settings - Fork 1
/
getdrives.m
69 lines (61 loc) · 2.02 KB
/
getdrives.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
61
62
63
64
65
66
67
68
69
function ret = getdrives(varargin)
%GETDRIVES Get the drive letters of all mounted filesystems.
% F = GETDRIVES returns the roots of all mounted filesystems as a cell
% array of char arrays.
%
% On Windows systems, this is a list of the names of all single-letter
% mounted drives.
%
% On Unix systems (including Macintosh) this is the single root
% directory, /.
%
% F = GETDRIVES('-nofloppy') does not scan for the a: or b: drives on
% Windows, which usually results in annoying grinding sounds coming from
% the floppy drive.
%
% F = GETDRIVES('-twoletter') scans for both one- AND two-letter drive
% names on Windows. While two-letter drive names are technically supported,
% their presence is in fact rare, and slows the search considerably.
%
% Note that only the names of MOUNTED volumes are returned. In
% particular, removable media drives that do not have the media inserted
% (such as an empty CD-ROM drive) are not returned.
%
% See also EXIST, COMPUTER, UIGETFILE, UIPUTFILE.
% Copyright 2001-2009 The MathWorks, Inc.
% Short-circut on non-Windows machines.
if ~ispc
ret = {'/'};
return;
end
twoletter = false;
nofloppy = false;
% Interpret optional arguments
for i = 1:nargin
if strcmp('-nofloppy', varargin{i}), nofloppy = true; end
if strcmp('-twoletter', varargin{i}), twoletter = true; end
end
% Initialize return cell array
ret = {};
% Handle -nofloppy flag, or lack thereof.
startletter = 'a';
if nofloppy
startletter = 'c';
end
% Look for single-letter drives, starting at a: or c: as appropriate
for i = double(startletter):double('z')
if exist(['' i ':\'], 'dir') == 7
ret{end+1} = [i ':\']; %#ok<AGROW>
end
end
% Handle two-letter case. The outer loop of this routine could have been
% combined with the one above, but was left separate for clarity's sake.
if twoletter
for i = 'a':'z'
for j = 'a':'z'
if exist([i j ':\'], 'dir') == 7
ret{end+1} = [i j ':\']; %#ok<AGROW>
end
end
end
end