File tree Expand file tree Collapse file tree 4 files changed +38
-31
lines changed Expand file tree Collapse file tree 4 files changed +38
-31
lines changed Original file line number Diff line number Diff line change 11%% DOTNET.DISK_AVAILABLE find the disk space available to the user
22
3- function f = disk_available(file )
4- arguments
5- file (1 ,1 ) string
6- end
3+ function i = disk_available(file )
74
8- f = uint64([]);
5+ try
6+ i = System .IO .DriveInfo(file ).AvailableFreeSpace();
7+ % https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.availablefreespace
8+ catch e
9+ switch class(e .ExceptionObject )
10+ case {' System.IO.DriveNotFoundException' , ' System.ArgumentException' }, i = [];
11+ otherwise , rethrow(e )
12+ end
13+ end
914
10- if ~ stdlib .exists( file ), return , end
15+ i = uint64( i );
1116
12- f = uint64(System .IO .DriveInfo(stdlib .absolute(file )).AvailableFreeSpace());
13- % https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.availablefreespace
1417end
Original file line number Diff line number Diff line change 11%% DOTNET.DISK_CAPACITY find the overall disk capacity visible to user
22
3- function f = disk_capacity(file )
4- arguments
5- file (1 ,1 ) string
6- end
7-
8- f = uint64([]);
9-
10- if ~stdlib .exists(file ), return , end
3+ function i = disk_capacity(file )
114
12- f = uint64(System .IO .DriveInfo(stdlib .absolute(file )).TotalSize());
5+ try
6+ i = System .IO .DriveInfo(file ).TotalSize();
137% https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.totalsize
8+ catch e
9+ switch class(e .ExceptionObject )
10+ case {' System.IO.DriveNotFoundException' , ' System.ArgumentException' }, i = [];
11+ otherwise , rethrow(e )
12+ end
13+ end
14+
15+ i = uint64(i );
1416
1517end
Original file line number Diff line number Diff line change 11%% DOTNET.FILESYSTEM_TYPE type of the partition e.g. NTFS, ext4, ...
22
33function t = filesystem_type(file )
4- arguments
5- file (1 ,1 ) string
6- end
74
8- if stdlib .exists(file )
9- t = char(System .IO .DriveInfo(stdlib .absolute(file )).DriveFormat);
10- % https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
11- else
5+ % https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.driveformat
6+
7+ try
8+ t = char(System .IO .DriveInfo(file ).DriveFormat);
9+ catch e
10+ switch class(e .ExceptionObject )
11+ case {' System.IO.DriveNotFoundException' , ' System.ArgumentException' }
12+ otherwise , rethrow(e )
13+ end
1214 t = ' ' ;
1315end
1416
Original file line number Diff line number Diff line change 33% Ref: https://learn.microsoft.com/en-us/dotnet/api/system.io.drivetype
44
55function y = is_removable(filepath )
6- arguments
7- filepath (1 ,1 ) string
8- end
96
10- if stdlib .exists( filepath )
11- fmt = System .IO .DriveInfo(stdlib .absolute( filepath ) ).DriveType;
7+ try
8+ fmt = System .IO .DriveInfo(filepath ).DriveType;
129 y = any(isequal(fmt , {System .IO .DriveType .Removable , ...
1310 System .IO .DriveType .CDRom }));
14- else
15- y = false ;
11+ catch e
12+ switch class(e .ExceptionObject )
13+ case {' System.IO.DriveNotFoundException' , ' System.ArgumentException' }, y = false ;
14+ otherwise , rethrow(e )
15+ end
1616end
1717
1818end
You can’t perform that action at this time.
0 commit comments