Main Content



Information on next file or file chunk


fileInfo = nextfile(fs)


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 To create a FileSet object, see

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.


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 =,...

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

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


  • 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