File tree Expand file tree Collapse file tree 3 files changed +37
-10
lines changed Expand file tree Collapse file tree 3 files changed +37
-10
lines changed Original file line number Diff line number Diff line change 11%% DEVICE filesystem device index of path
2- % requires: java
3- % Windows always returns 0, Unix returns device number.
2+ % optional: java
43
54function i = device(path )
65arguments
98
109i = [];
1110
12- if stdlib .isoctave()
11+ if ispc()
12+ h = NET .addAssembly(' System.Management' );
13+
14+ r = stdlib .root_name(path );
15+ queryLogicalDisk = sprintf(' SELECT VolumeSerialNumber FROM Win32_LogicalDisk WHERE Caption = ''%s'' ' , r );
16+
17+ % Create a ManagementObjectSearcher instance
18+ searcher = System .Management .ManagementObjectSearcher(queryLogicalDisk );
19+
20+ % Get the collection of ManagementObject instances
21+ logicalDisks = searcher .Get();
22+
23+ % Get the first result (should be at most one for a drive letter)
24+ logicalDiskEnumerator = logicalDisks .GetEnumerator();
25+ if logicalDiskEnumerator .MoveNext()
26+ logicalDisk = logicalDiskEnumerator .Current ;
27+
28+ % Get the VolumeSerialNumber property
29+ % This property is a string in WMI, representing a 32-bit hexadecimal integer.
30+ i = hex2dec(char(logicalDisk .GetPropertyValue(' VolumeSerialNumber' )));
31+ end
32+
33+ delete(h )
34+ elseif stdlib .isoctave()
1335 [s , err ] = stat(path );
1436 if err == 0
1537 i = s .dev ;
Original file line number Diff line number Diff line change @@ -49,5 +49,17 @@ function test_filesystem_type(tc, Ps)
4949end
5050end
5151
52+
53+ function test_device(tc )
54+
55+ if ispc()
56+ tc .verifyGreaterThan(stdlib .device(pwd()), 0 )
57+ else
58+ tc .assumeGreaterThanOrEqual(stdlib .java_api(), 11 )
59+
60+ tc .verifyEqual(stdlib .device(" ." ), stdlib .device(pwd()))
61+ end
62+ end
63+
5264end
5365end
Original file line number Diff line number Diff line change @@ -15,13 +15,6 @@ function test_inode(tc)
1515end
1616
1717
18- function test_device(tc )
19- tc .assumeFalse(ispc(), " not for Windows" )
20- tc .assumeGreaterThanOrEqual(stdlib .java_api(), 11 )
21-
22- tc .verifyEqual(stdlib .device(" ." ), stdlib .device(pwd()))
23- end
24-
2518function test_owner(tc , Ps )
2619
2720s = stdlib .get_owner(Ps );
You can’t perform that action at this time.
0 commit comments