Main Content

nextfile

Class: matlab.io.datastore.DsFileSet
Namespace: matlab.io.datastore

Information on next file or file chunk

Syntax

fileInfo = nextfile(fs)

Description

fileInfo = nextfile(fs) returns the information on the next file available in the file set object fs. Subsequent calls to the nextfile function continue reading from the endpoint of the previous call.

Input Arguments

expand all

Input file-set object, specified as a DsFileSet or FileSet object. To create a DsFileSet object, see matlab.io.datastore.DsFileSet. To create a FileSet object, see matlab.io.datastore.FileSet.

Output Arguments

expand all

File information, returned as a table. The table contains columns FileName, FileSize, Offset, and SplitSize for DSFileSet. File information is returned as a FileInfo object for a FileSet object with fields Filename and FileSize.

Examples

Get File Information One File at a Time

Create a file-set object and get the file information iteratively, one file at a time.

Create a file-set object for all .mat files in the demos folder.

folder = fullfile(matlabroot,'toolbox','matlab','demos');
fs = matlab.io.datastore.DsFileSet(folder,...
                 'IncludeSubfolders',true,...
                 'FileExtensions','.mat');

Get the file information from the file-set object fs, one file at a time.

while hasfile(fs)
   file = nextfile(fs);
end

Tips

  • The nextfile method returns an error if no more files exist in the file-set object fs. To avoid this error, use nextfile along with hasfile and reset. The hasfile method checks if files still remain in the file-set object, while the reset method resets the internal file pointer to the beginning of the file-set object.

Version History

Introduced in R2017b