|
|
|
|
- Overview
- Method 1: Retrieving the list of files directly
- Method 2: Using a "Callback" procedure to process each file independently
How to loop through the files of a directory?
To browse the files found in a directory, you must use fListFile. This function is used to: - list all the files found in a directory and in its sub-directories.
- list the files found in a directory without going into the sub-directories.
- list the files with a filter (extension and/or name).
Two methods are available: Method 1: Retrieving the list of files directly To directly retrieve the list of files: - Retrieve in a character string the list of all files by using fListFile.
- Browse the retrieved string in a loop. Each file is separated by a CR character.
- Process each file found.
Code example:
sFileList is string sFile is string sFileList = fListFile("C:\TEMP\*.DOC") FOR EACH STRING sFile OF sFileList SEPARATED BY CR // Process the sFile file // the sFile variable contains the name of file to process END
Method 2: Using a "Callback" procedure to process each file independently To process each listed file independently via a WLanguage procedure: - Create a local or internal procedure to process each file found.
- Browse the list of all files by using fListFile associated with the procedure that was created beforehand.
Code example:
INTERNAL PROCEDURE pProcessFile(sDir, sFile) // Process the file found // The sDir variable contains the file directory // The sFile variable contains the name of the file Trace(sDir, sFile) END fListFile("C:\TEMP\*.DOC", pProcessFile)
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|