CFileDlg:Start CFileDlg:Save

CFileDlg:Next


The Next method returns the next file name in the list of names returned by the Open method. This is an iterator to fetch the next name in a list. The iteration must be started using the Start method.

Syntax

sFileName = CFileDlg:Next()

    sFileName is the returned path string for the file. When done, nil is returned.

Remarks

This method advances to the next file name and returns it. If another file name is found, the full path (machine, drive, folder, file name, and extension) is returned. If no more file names are found, nil is returned. The search must have been initialized using the Start method before Next is called. The returned file names might be used immediately or be stored in an indexed table for later use. The example below stores the values in an indexed table from which you can later fetch the n-th file name using FileName[i].

Example

The following example uses Next to loop over 100 files and store the returned file names in a table:

F = CFileDlg:new()

-- create a CFileDlg object

 

F.bSetMaxFiles = true

-- set the flag for selecting more than 1 file

F.nMaxFiles = 100

-- allow selecting up to 100 files

sName, bSuccess = F:Open()

-- get a file name

-- create a table to hold the names of the selected files

FileName = {}

-- create the table

n = 1

-- setup an index counter

F:Start()

-- initialize the file name iteration

while true do

-- loop through the selected files:

  FileName[n] = F:Next()

-- put file name into table

  n = n + 1

-- increment the table index

end

 

Related Topics

CFileDlg, Open, Start