Code covered by the BSD License  

Highlights from
Readtext wrapper

Readtext wrapper

by

 

07 Jan 2010 (Updated )

A wrapper for READTEXT which builds it in smaller chunks (reduces peak memory footprint).

getfilesize(fileName)
function fileSize = getfilesize(fileName)
% GETFILESIZE returns the size of a file

% checks the number of arguments
error(nargchk(1, 1, nargin))

% checks the filename is a string
if ~ischar(fileName) || size(fileName, 1) ~= 1
    % errors
    error('Filename must be a string.')
end

% gets info on the file
dirStruct = dir(fileName);

% providing its not empty... (quicker than testing if the file exists)
if ~isempty(dirStruct)
    % return the file size
    fileSize = dirStruct.bytes;
    
else
    % errors since the file does not exist
    error('File does not appear to exist.')
end

Contact us