Matlab 检查文件的大小
我想检查一下文件的大小 如果我使用Matlab 检查文件的大小,matlab,Matlab,我想检查一下文件的大小 如果我使用 aux = dir(diary_file); sizeOfFile = aux.bytes; bytes: 362 现在我想检查文件的大小是否大于1,我该怎么做呢除非我在这里遗漏了一些东西,这很简单: if sizeOfFile > 1 disp('Size of file is greater than 1'); % or do whatever else you want in that case else disp('Size of
aux = dir(diary_file);
sizeOfFile = aux.bytes;
bytes: 362
现在我想检查文件的大小是否大于1,我该怎么做呢除非我在这里遗漏了一些东西,这很简单:
if sizeOfFile > 1
disp('Size of file is greater than 1'); % or do whatever else you want in that case
else
disp('Size of file is less or equal to 1'); % or do whatever else you want in that case
end
为了好玩,这里有一个稍微防白痴的版本:
try
aux = dir(diary_file);
catch ME
ME2 = MException('insert:id', 'Could not get directory listing for file/dir:');
throw(addCause(ME2, ME));
end
if ~isempty(aux)
if numel(aux) == 1
sz = aux.bytes;
elseif aux.isdir
error('insert:id', 'Expected single file; got directory listing.');
else
error('insert:id', 'Inconsistent directory listing.');
end
if ispc
[~,~,ext] = fileparts(aux.name);
if strcmpi(ext, '.lnk')
warning('insert:id', ...
'File seems to be a link; size may be misrepresented.');
end
end
if sz > 1
% CHECK PASSED
else
% CHECK NOT PASSED
end
else
error('insert:id', 'File does not exist.');
end
可能重复@shakthydoss:不是重复的——他/她在问如何检查变量是否大于1。我结束发言是因为对这个问题似乎没有一点了解。