Main Content



Determine if more files are available in file-set object


tf = hasfile(fs)


tf = hasfile(fs) returns logical 1 (true) if any more files are available to process in the DsFileSet object specified by fs. Otherwise, it returns logical 0 (false).

Input Arguments

expand all

Input file set, specified as a object. To create a DsFileSet object, see

Example: hasfile(fs)


Check if File-set Object has More Files

Create a file-set object, check if the file-set object has any files, and then read the data iteratively.

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

folder = fullfile(matlabroot,'toolbox','matlab','demos');
fs =,...

Use the hasfile method to check if the file-set object has more files to read. Get the file information, one file at a time, while files remain in the file-set object.

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

Introduced in R2017b