Skip to content

Commit 9c03f88

Browse files
committed
dotnet disk* simplify
1 parent 0bd985b commit 9c03f88

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

+stdlib/+dotnet/disk_available.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
function i = disk_available(file)
44

5-
% Windows needs exists() not just strempty()
6-
if stdlib.has_dotnet() && stdlib.exists(file)
7-
% absolutizing is necessary for Windows especially
8-
i = System.IO.DriveInfo(System.IO.Path.GetFullPath(file)).AvailableFreeSpace();
9-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.availablefreespace
10-
i = uint64(i);
11-
else
12-
i = missing;
13-
end
5+
i = disk_usage(file, 'available');
146

157
end

+stdlib/+dotnet/disk_capacity.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
function i = disk_capacity(file)
44

5-
% Windows needs exists() not just strempty()
6-
if stdlib.has_dotnet() && stdlib.exists(file)
7-
% absolutizing is necessary for Windows especially
8-
i = System.IO.DriveInfo(System.IO.Path.GetFullPath(file)).TotalSize();
9-
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.totalsize
10-
i = uint64(i);
11-
else
12-
i = missing;
13-
end
5+
i = disk_usage(file, 'capacity');
146

157
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function i = disk_usage(file, v)
2+
3+
% Windows needs exists() not just strempty()
4+
if stdlib.has_dotnet() && stdlib.exists(file)
5+
% absolutizing is necessary for Windows especially
6+
di = System.IO.DriveInfo(System.IO.Path.GetFullPath(file));
7+
8+
switch v
9+
case 'available', i = di.AvailableFreeSpace();
10+
case 'capacity', i = di.TotalSize();
11+
otherwise, error('stdlib:dotnet:disk_usage:valueError', 'unknown disk_usage property %s', v)
12+
end
13+
% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.totalsize
14+
i = uint64(i);
15+
else
16+
i = missing;
17+
end
18+
19+
end

0 commit comments

Comments
 (0)