IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Téléchargé 1 fois
Vote des utilisateurs
0 
0 
Détails
Licence : BSD
Mise en ligne le 4 juin 2014
Plate-forme : Windows
Langue : Français
Référencé dans
Navigation

Identification du type de lecteur (amovible, fixe, CD-ROM...)

Voici un code MATLAB permettant d'identifier le type d'un lecteur sous Windows.

Le code utilise l'API Windows via un fichier C-MEX

Le fichier source C-MEX ainsi que les versions compilées 32 et 64 bits sont fournis.

%GETDRIVETYPE Disk drive type
% DT = GETDRIVETYPE(S) determines whether the disk drives contained in S
% are removable, fixed, CD-ROM, RAM disk, or network drives. S is a
% character array or a cell array of strings containing standard drive
% letters as A:\, B:\, C:\, D:\ ... For each entry of S, DT is one of :
%
% 1 : 'Unknown'
% 2 : 'Invalid root path'
% 3 : 'Removable media'
% 4 : 'Fixed media'
% 5 : 'Remote drive'
% 6 : 'CD-ROM drive'
% 7 : 'RAM disk'
%
% Exemples :
%
% DT = getdrivetype('C:\')
%
% DT =
%
% 4
%
% DT = getdrivetype('F:\')
%
% DT =
%
% 6
%
% See Win32 API reference for more informations :
% http://msdn.microsoft.com/en-us/library/aa364939%28VS.85%29.aspx
%
% GETDRIVETYPE works only on PC (Windows).
Avatar de Jerome Briot
Rédacteur/Modérateur https://www.developpez.com
Le 06/06/2013 à 12:27
Ce code fonctionne bien avec la contribution : [Windows] Liste des lecteurs disponibles (amovible, fixe, CD-ROM...)

Voici un exemple sur mon ordinateur portable avec deux partitions, un lecteur DVD et une clé USB connectée :

Code : Sélectionner tout
1
2
3
4
5
6
7
8
9
D = getlogicaldrives;

typs = {'Unknown' 'Invalid root path' 'Removable media' 'Fixed media' ...
    'Remote drive' 'CD-ROM drive' 'RAM disk'};

for n = 1:numel(D)
    t = getdrivetype(D{n});
    fprintf('Le lecteur %s est de type : %s\n',D{n},typs{t})
end
renvoie :
Code : Sélectionner tout
1
2
3
4
Le lecteur C:\ est de type : Fixed media
Le lecteur D:\ est de type : Fixed media
Le lecteur E:\ est de type : CD-ROM drive
Le lecteur F:\ est de type : Removable media
Avatar de Jerome Briot
Rédacteur/Modérateur https://www.developpez.com
Le 06/06/2013 à 13:00
Une autre fonction dérivée qui teste si un lecteur est un lecteur CD/DVD :
Code : Sélectionner tout
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
function result = iscdrom(S)
%ISCDROM True for CD-ROM drive letter
% ISCDROM(S) returns 1 if the drive with letter S is a CD-ROM drive. S is a
% character array or a cell array of strings containing standard drive
% letters as A:\, B:\, C:\, D:\ ...
%
%   Exemples :
%
%    iscdrom('F:\')
% 
%     ans =
% 
%          1
%
%    iscdrom({'A:\' 'C:\' 'F:\'})
% 
%     ans =
% 
%          0     0     1
%
%   ISCDROM works only on PC (Windows).
%
%   See also findcdromdrive, getdrivetype, getlogicaldrives.
%

%   Author: Jerome Briot (MATLAB R2009a)
%   http://www.developpez.net/forums/member.php?u=125006
%   http://www.mathworks.com/matlabcentral/fileexchange/authors/21984
%   Contact: dutmatlab#at#yahoo#dot#fr
%   Revision: 1.0 (08-Mar-2011)
%   Comments:
%

if ~ispc
    error('ISCDROM works only on PC (Windows)');
end

result = getdrivetype(S) == 6;
En reprenant l'exemple précédent :
Code : Sélectionner tout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
>> iscdrom('E:\')

ans =

     1

>> iscdrom('F:\')

ans =

     0

>> D = getlogicaldrives

D = 

    'C:\'    'D:\'    'E:\'    'F:\'

>> iscdrom(D)

ans =

     0     0     1     0
Avatar de Jerome Briot
Rédacteur/Modérateur https://www.developpez.com
Le 06/06/2013 à 13:45
Et l'inverse :

Code : Sélectionner tout
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
function L = findcdromdrive
%FINDCDROMDRIVE CD-ROM drive letters.
% L = FINDCDROMDRIVE returns the letters of the currently available CD-ROM 
% drives in the cell array of strings L.
%
%   Exemples :
%
%     L = findcdromdrive
% 
%     L = 
% 
%         'F:\'    'G:\'
%
%   FINDCDROMDRIVE works only on PC (Windows).
%
%   See also iscdrom.
%

%   Author: Jerome Briot (MATLAB R2009a)
%   http://www.developpez.net/forums/member.php?u=125006
%   http://www.mathworks.com/matlabcentral/fileexchange/authors/21984
%   Contact: dutmatlab#at#yahoo#dot#fr
%   Revision: 1.0 (08-Mar-2011)
%   Comments:
%

if ~ispc
    error('FINDCDROMDRIVE works only on PC (Windows).');
end

d = getlogicaldrives;
idx = iscdrom(d);

L = d(idx);
Toujours avec le même exemple :
Code : Sélectionner tout
1
2
3
4
5
>> L = findcdromdrive

L = 

    'E:\'
Developpez.com décline toute responsabilité quant à l'utilisation des différents éléments téléchargés.