Main Content

hasNextFile

Determine if file-set has another file in file-set

Since R2020a

Description

example

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

Examples

collapse all

Check if a file-set has another file and read the data iteratively.

Create a file-set fs for a collection of files.

folder = {'accidents.mat','airlineResults.mat','census.mat','earth.mat'}
folder = 1x4 cell
    {'accidents.mat'}    {'airlineResults.mat'}    {'census.mat'}    {'earth.mat'}

fs = matlab.io.datastore.FileSet(folder)
fs = 
  FileSet with properties:

                    NumFiles: 4
                NumFilesRead: 0
                    FileInfo: Show FileInfo for all 4 files
    AlternateFileSystemRoots: {}

Use the hasNextFile and nextfile functions to read file information one file at a time while files remain in the set.

while hasNextFile(fs)
   file = nextfile(fs)
end
file = 
  1x1 FileInfo
                                       Filename                                       FileSize
    ______________________________________________________________________________    ________

    "/mathworks/devel/bat/Bdoc23a/build/matlab/toolbox/matlab/demos/accidents.mat"      7343  

file = 
  1x1 FileInfo
                                         Filename                                           FileSize 
    ___________________________________________________________________________________    __________

    "/mathworks/devel/bat/Bdoc23a/build/matlab/toolbox/matlab/demos/airlineResults.mat"    1.5042e+05

file = 
  1x1 FileInfo
                                     Filename                                      FileSize
    ___________________________________________________________________________    ________

    "/mathworks/devel/bat/Bdoc23a/build/matlab/toolbox/matlab/demos/census.mat"      353   

file = 
  1x1 FileInfo
                                     Filename                                     FileSize
    __________________________________________________________________________    ________

    "/mathworks/devel/bat/Bdoc23a/build/matlab/toolbox/matlab/demos/earth.mat"     32522  

Input Arguments

collapse all

File-set, specified as a FileSet object. To create a FileSet object, see matlab.io.datastore.FileSet.

Version History

Introduced in R2020a