Exit GetFileName

GetFileList


The GetFileList function returns a lua table containing the full path name for files in a folder. The names are full path names including the full path. The names must match the specified template, which can be simply "*.*". Also see the CFindFiles class for another way to collect files from a folder.

Syntax

nFiles = GetFileList( sFolder, sTemplate, tblNames )

bullet.gif    sFolder is the folder to search.

bullet.gif    sTemplate is the name pattern to match.

bullet.gif    tblNames is a table containing the file names, including the full path.

bullet.gif    On success, nFiles > 0 and tblNames contains an array of file name strings.

bullet.gif    On failure, nFiles=0.

Example

This example selects a target folder, matches all FITS image files matching the template "*.fts" and then lists them. Note that the entire for loop could be replaced by list(tbl) but the latter method does not permit formatting using Printf.

 

-- get the folder

 

 

sStart = "C:\\Downloads"

-- default location

 

sFolder, bOK = GetFolder(sStart)

-- select folder in GetFolder()

 

if not bOK then Exit("aborted\n") end

 

 

-- find all "*.fts" files in the folder

 

 

tbl = {}

-- create a table for the file names

 

sTemplate = "*.fts"

-- find files of this type

 

nFiles = GetFileList( sFolder, sTemplate, tbl )

-- return the table of file names

 

Printf("%d %s files found\n", nFiles, sTemplate)

 

 

-- list the file names from the table:

 

 

for k=1, nFiles do

 

 

  Printf("%d: %s\n", k, tbl[k] )

 

 

end

 

 

Related Topics

Directory Functions

CFindFiles

GetFolder

GetFileName

 


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.