hasPreviousFile

Determine if a file-set has a previous file

Description

example

tf = hasPreviousFile(fs) returns logical 1 (true) if a previous file is 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 a previous file available to process.

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

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

    {'accidents.mat'}    {'airlineResults...'}    {'census.mat'}

  Column 4

    {'earth.mat'}

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

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

Get the information for the first file and move the internal pointer forward one file.

file1 = nextfile(fs)
file1 = 
  1x1 FileInfo
                                       Filename                                       FileSize
    ______________________________________________________________________________    ________

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

Get information for the second file and move the internal pointer forward one file.

file2 = nextfile(fs)
file2 = 
  1x1 FileInfo
                                         Filename                                           FileSize 
    ___________________________________________________________________________________    __________

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

Check to see if a previous file exists. In this case, the result is true because a previous file exists.

tf = hasPreviousFile(fs)
tf = logical
   1

Input Arguments

collapse all

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

Introduced in R2020a