Main Content

hasfile

Class: matlab.io.datastore.DsFileSet
Package: matlab.io.datastore

Determine if more files are available in file-set object

Syntax

tf = hasfile(fs)

Description

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 matlab.io.datastore.DsFileSet object. To create a DsFileSet object, see matlab.io.datastore.DsFileSet.

Example: hasfile(fs)

Examples

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 = matlab.io.datastore.DsFileSet(folder,...
                 'IncludeSubfolders',true,...
                 'FileExtensions','.mat');

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);
end

Introduced in R2017b