PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK

  • Procedure that handles each listed file (syntax 2 only)
  • Full interruption of fListFile (syntax 2)
  • Partial interruption of fListFile (syntax 2)
  • Managing errors
  • Listing the subdirectories of a directory
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Lists the files found in a directory and returns the list of files. The listed files are sought from the given directory.
Other use: For each file found, fListFile can automatically call a specific procedure written in WLanguage. This procedure is used to handle the current file. In this case, fListFile returns the number of listed files.
Note: In 64-bit Windows, the access to a system directory from a 32-bit executable can be performed in a directory that differs from the expected one. See Native 64-bit and native 32-bit for more details.
Versions 16 and later
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for the Windows Phone applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
Stored procedures This function is now available in the code of stored procedures.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Stored procedures This function is now available in the code of stored procedures.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Stored procedures This function is now available in the code of stored procedures.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
WINDEVUser code (UMC)
AFile, ResFileList are strings
// Lists the ".BMP" files found in "C:\MyDocuments".
// The browse is also performed in the sub-directories and it can be interrupted.
ResFileList = fListFile("\MyDocuments\*.BMP", frRecursive + frInterruptible)
// For each file found
FOR EACH STRING AFile OF ResFileList SEPARATED BY CR
// Add the file into TABLE_FileTable
TableAdd(TABLE_FileTable, AFile)
END
WINDEVJavaUser code (UMC)
// Lists the ".BMP" files found in "C:\MyDocuments".
// The FileAttribute procedure returns the number of read-only files.
ResFileList = fListFile("C:\MyDocuments\*.BMP", "FileAttribute")
Syntax

Listing the files found in a directory Hide the details

<Result> = fListFile(<Path and generic name of files> , <Options>)
<Result>: Character string
Full name of listed files, separated by CR characters (Carriage Return).

Caution: The function can return files whose short name corresponds to the filter used (while the long name does not correspond to this filter).
<Path and generic name of files>: Character string (with quotes)
Path and generic name of files to list. The generic characters (* and?) are allowed. Special cases:
  • if the directory and the drive are not specified: the search path is built from the current drive and from the current directory for this drive.
  • if the drive is not specified while the directory is specified: the search path is built from the current drive and from the directory passed in parameter.
  • if the drive is specified while the directory is not specified, the search path is built from the specified drive and from the current directory for this drive.
Versions 15 and later
WindowsLinux This parameter can be in Ansi or Unicode format.
New in version 15
WindowsLinux This parameter can be in Ansi or Unicode format.
WindowsLinux This parameter can be in Ansi or Unicode format.
Versions 16 and later
Universal Windows 10 App In Windows Phone: The file path corresponds to a relative path in relation to the current directory. The current directory corresponds to the data directory of application.
Reminder: In Windows Phone, only the files found in the data directory associated with the application can be handled.
New in version 16
Universal Windows 10 App In Windows Phone: The file path corresponds to a relative path in relation to the current directory. The current directory corresponds to the data directory of application.
Reminder: In Windows Phone, only the files found in the data directory associated with the application can be handled.
Universal Windows 10 App In Windows Phone: The file path corresponds to a relative path in relation to the current directory. The current directory corresponds to the data directory of application.
Reminder: In Windows Phone, only the files found in the data directory associated with the application can be handled.
<Options>: Combination of Integer constants
Option used to define the information returned as well as the type of browse performed for the directory files:
Versions 15 and later
fPathUNICODE
New in version 15
fPathUNICODE
fPathUNICODE
<Result> will be a string in Unicode format.
Versions 16 and later
Universal Windows 10 App This constant is ignored in Windows Phone.
New in version 16
Universal Windows 10 App This constant is ignored in Windows Phone.
Universal Windows 10 App This constant is ignored in Windows Phone.
fdFullInformationEach line (separated by carriage return - CR) contains the following information:

<Full File Name> + TAB + <Size in Bytes> + TAB + <Date of Last Modification> + TAB + <File Attributes>

The date is in YYYYMMDDHHMMSS format. The attributes are identical to the ones returned by fAttribute.
Versions 16 and later
Universal Windows 10 App This constant is ignored in Windows Phone.
New in version 16
Universal Windows 10 App This constant is ignored in Windows Phone.
Universal Windows 10 App This constant is ignored in Windows Phone.
fdInterruptibleThe browse can be interrupted by pressing the ESC key. The function will return the name of the listed files until the interruption.
LinuxUniversal Windows 10 App This constant has no effect in Windows Phone and Windows Store apps.
frNotRecursiveThe browse is a non-recursive browse. Subdirectories are ignored.
frRecursive
(Default value)
The browse is a recursive browse. The sub-directories are automatically taken into account.
frNoHiddenFileIf the frFullInformation constant is used, the hidden files are not listed (attribute = "H").
Versions 16 and later
Universal Windows 10 App This constant is ignored in Windows Phone.
New in version 16
Universal Windows 10 App This constant is ignored in Windows Phone.
Universal Windows 10 App This constant is ignored in Windows Phone.
frNoHiddenDirectoryIf the frFullInformation constant is used, the hidden directories are not listed (attribute = "H").
Versions 16 and later
Universal Windows 10 App This constant is ignored in Windows Phone.
New in version 16
Universal Windows 10 App This constant is ignored in Windows Phone.
Universal Windows 10 App This constant is ignored in Windows Phone.

WINDEVJavaUser code (UMC)

Listing the files found in a directory by calling a procedure for each file Hide the details

<Result> = fListFile(<Path and generic name of files> , <Procedure name> [, <Pointer> [, <Options>]])
<Result>: Integer
Number of listed files.
<Path and generic name of files>: Character string (with quotes)
Path and generic name of files to list. The generic characters (* and?) are allowed. Special cases:
  • if the directory and the drive are not specified: the search path is built from the current drive and from the current directory for this drive.
  • if the drive is not specified while the directory is specified: the search path is built from the current drive and from the directory passed in parameter.
  • if the drive is specified while the directory is not specified, the search path is built from the specified drive and from the current directory for this drive.
<Procedure name>: Character string (with or without quotes)
Name of WLanguage procedure ("callback" procedure) that will be called for each listed file. This procedure is used to handle the current file.
This procedure has the following format:
PROCEDURE <Procedure name> (<Path>, <File name>,
<Change>, <Procedure pointer>)

The parameters of this procedure are optional.
There is no need to pass parameters to this procedure. Indeed, these parameters are automatically filled whenever a file is processed.
<Pointer>: Optional integer
Pointer passed to <Procedure name>.
<Options>: Optional Integer constant (or combination of constants)
Type of browse performed for the directory files:
Versions 15 and later
fPathUNICODE
New in version 15
fPathUNICODE
fPathUNICODE
<Result> will be a string in Unicode format.
fdInterruptibleThe browse can be interrupted by pressing the ESC key.
Linux This constant has no effect.
frNotRecursiveThe browse is a non-recursive browse. Subdirectories are ignored.
frRecursive
(Default value)
The browse is a recursive browse. The sub-directories are automatically taken into account.
Remarks

Procedure that handles each listed file (syntax 2 only)

For each file found, fListFile automatically calls the <Procedure name> procedure. This procedure is a local or global procedure.
To create this procedure:
  1. Create a global procedure ("Insert .. New global procedure" in the code editor).Create a global procedure (from the code editor: on the "Code" pane, in the "Procedures" group, expand "New" and select "New global procedure").
  2. Fill the procedure declaration as follows:
PROCEDURE <Procedure name> (<Path>, <File name>,
<Change>, <Procedure pointer>)
  • <Path> is the path of file used (it always ends with a "\" character ; for example, "C:\WINDEV\").
  • <File name> is a character string containing the name of file found.
  • <Change> is a constant set to:
    • flFirstFile when the file is the first file listed in <Path>,
    • flChangeDir when the file is the first file listed in a sub-directory of <Path> (which means that a change of directory occurred),
    • flFile in all the other cases.
    The different values that can be taken by <Change> are as follows:
    Current file<Change>
    Dir\File 1flFirstFile
    Dir\File nflFile
    Dir\SubDir 1\File 1flChangeDir
    Dir\SubDir 1\File mflFile
    Dir\SubDir 2\File 1flChangeDir
    Dir\SubDir 2\File xflFile
  • <Procedure pointer> is an integer whose value is the one passed to the <Pointer> parameter of fListFile. If <Pointer> is not specified, <Pointer> is set to 0.
To retrieve the value of <Procedure pointer>, assign its value to the value of <Pointer> in the procedure with Transfer (see the detailed example at the top of the page).
Note: The parameters of this procedure are optional: you have the ability to specify the name and the path for example.

Full interruption of fListFile (syntax 2)

fListFile cannot be interrupted as long as there are files to browse.
To force the interruption of the browse, use the following code line in the <Procedure name> procedure:
RESULT False
For example, the "FindProduct" procedure is automatically called by fListFile:
PROCÉDURE FindProduct(Path, FileName)
...
// Stop requested?
Multitask(-1)
IF KeyPressed(kpEscape) = True THEN
Info("The search will be stopped")
RESULT False
END
...
RESULT True
In this case, fListFile returns the number of files browsed until the call to "Result False".
In any other case (to continue the browse), <Procedure name> MUST return True.
An error is generated if <Procedure name> returns no value (neither True nor False).

Partial interruption of fListFile (syntax 2)

In order for the <Procedure Name> procedure not to be run for a given file, use the following code line:
RESULT True
For example, the "FindProduct" procedure is automatically called by fListFile:
PROCÉDURE FindProduct(Path, FileName)
...
// File to ignore
IF FileName = "WrongFile.XLS" THEN
RESULT True
END
...
RESULT True
In this case, fListFile automatically calls the <Procedure name> procedure for the next listed file.
An error is generated if <Procedure name> returns no value (neither True nor False).

Managing errors

Caution: fListFile returns no error code. To find out whether an error was generated by this function, use ErrorInfo with the errMessage constant.
WINDEVJavaUser code (UMC)

Listing the subdirectories of a directory

To list the sub-directories of a directory, use fListDirectory.
Tip: fListFile can also be used to list the sub-directories of a directory.
Example:
fListFile("c:\temp\anim\.", proc)
// Don't forget the '.' at the end of string to identify the directories
PROCÉDURE proc(Dir, file, nChange, ptr)
Trace(Dir)
Related Examples:
The fListFile function Unit examples (WINDEV): The fListFile function
[ + ] Using fListFile and its syntax that directly returns the list of files/directories found in string format.
Component : wd240std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Video FlistFile
https://youtu.be/SE--Bx9Gq40
https://windevdesenvolvimento.blogspot.com/2019/09/dicas-2284-windev-webdev-mobile.html
//PROCEDURE LISTA_DIRETORIO()
s_ARQUIVOS_TODOS is string=fListDirectory(EDT_DIRETORIO)
s_ARQUIVO_INDIVIDUAL is string=""
TVT_DIRETORIO.DeleteAll()
FOR EACH STRING s_ARQUIVO_INDIVIDUAL OF s_ARQUIVOS_TODOS SEPARATED BY CR
n_POSICAO is int=TVT_DIRETORIO.AddLine() TVT_DIRETORIO.COL_01_DIRETORIO[n_POSICAO]=s_ARQUIVO_INDIVIDUAL
TVT_DIRETORIO[n_POSICAO]..AddChildDelayed=LISTA_SUB_DIRETORIO_1
END
LISTA_ARQUIVOS()
//
//PROCEDURE LISTA_ARQUIVOS()
TableDeleteAll(TABLE_ARQUIVOS)
s_ARQUIVOS_INDIVIDUAIS is string=fListFile(TVT_DIRETORIO.COL_01_DIRETORIO+"\*.*")
FOR EACH STRING sARQUIVO_ OF s_ARQUIVOS_INDIVIDUAIS SEPARATED BY CR
nPOSICAO is int=TABLE_ARQUIVOS.AddLine()
TABLE_ARQUIVOS[nPOSICAO].COL_ARQUIVO=sARQUIVO_
END
amarildo
11 Sep. 2019
EXEMPLO
https://youtu.be/1-Rhy8T5g-M

http://windevdesenvolvimento.blogspot.com/2018/04/dicas-1741-publica-windev-arquivos-25.html

https://groups.google.com/d/forum/amarildowindev
http://windevdesenvolvimento.blogspot.com/2018/01/inscricao-para-grupo-privado-amarildo.html
http://windevdesenvolvimento.blogspot.com.br/2017/07/menu-blog.html

// EXEMPLO

TableDeleteAll(TABLE_LISTA_ARQUIVOS)
s_arquivos_todos is string=fListFile(EDT_DIRETORIO+"*.*")
FOR EACH STRING s_arquivo_individual OF s_arquivos_todos SEPARATED BY CR
Message(s_arquivo_individual)
s_nome_arquivo is string=fExtractPath(s_arquivo_individual,fFileName+fExtension)
s_tamanho_arquivo is string=fSize(EDT_DIRETORIO+s_nome_arquivo)
dS_data_arquivo is Date=fDate(EDT_DIRETORIO+s_nome_arquivo)
hS_hora_arquivo is Time=fTime(EDT_DIRETORIO+s_nome_arquivo)
TableAddLine(TABLE_LISTA_ARQUIVOS,s_nome_arquivo,s_tamanho_arquivo,dS_data_arquivo,hS_hora_arquivo)

END
TableSort(TABLE_LISTA_ARQUIVOS,"-TABLE_lista_ar
De matos
29 May 2018
ARQUIVOS DIRETORIO
EDT_DIRETORIO = fSelectDir("", "")

s_arquivos_todos is string=fListFile(EDT_DIRETORIO+"\*.*")

s_arquivo_individual is string=""

FOR EACH STRING s_arquivo_individual OF s_arquivos_todos SEPARATED BY CR
gs_manifestacao="NAO"
EDT_xml_nome=s_arquivo_individual
EDT_xml=""
s_xml_documento is string=s_arquivo_individual
s_meu_xml is string=fLoadText(s_xml_documento)
IF s_meu_xml<>"" THEN
EDT_xml=s_meu_xml
_710_001_levar_notas_ind()
_801_Gravar_nota()
END
END
gb_importar_varios_xml=False
Info("Finalizado Importação ")

// BLOG COM EXEMPLO E VIDEO

https://www.youtube.com/watch?v=ccpqJG7a15I

http://windevdesenvolvimento.blogspot.com.br/2017/10/aula-1268-arquivos-022-ler-arquivos.html


De matos
04 Oct. 2017
Mostrar Arquivos de um Diretorio Ftp
PROCEDURE arquivo_mostra_local()
//leio o conteudo do diretorio e preencho tabela
TableDeleteAll(TABLE_local)
s_arquivo_individual is string=""
s_arquivo_todos is string=fListFile(ftp_conf.endereco_local+"*.*") // mostra arquivos diretorio
s_nome_arquivo is string=""
s_tamanho_arquivo is string=""
d_data_arquivo is Date=""
h_hora_arquivo is Time=""
_atributos_arquivo is string=""

FOR EACH STRING s_arquivo_individual OF s_arquivo_todos SEPARATED BY CR
s_nome_arquivo=fExtractPath(s_arquivo_individual,fFileName+fExtension)
s_tamanho_arquivo=fSize(ftp_conf.endereco_local+s_nome_arquivo)
d_data_arquivo=fDate(ftp_conf.endereco_local+s_nome_arquivo)
h_hora_arquivo=fTime(ftp_conf.endereco_local+s_nome_arquivo)
TableAddLine(TABLE_local,s_nome_arquivo,s_tamanho_arquivo,d_data_arquivo,h_hora_arquivo)
// outras informacoes uteis
_atributos_arquivo=fAttribut(ftp_conf.endereco_local+s_nome_arquivo) // atribuito arquivo
Info(fExtractPath(s_arquivo_individual,fDisque)) // drive
Info(fExtractPath(s_arquivo_individual,fExtension)) // extensao
Info(fExtractPath(s_arquivo_individual,fFichier)) // nome arquivo
Info(fExtractPath(s_arquivo_individual,fRépertoire)) // diretorio
Info(fExtractPath(s_arquivo_individual, fRépertoire)) // diretorio
END

//http://windevdesenvolvimento.blogspot.com.br/2016/01/windev21-curso-201-ftp-mostrar-arquivos.html
De matos AMARILDO
09 Feb. 2016
Exemplo de Mostrar Arquivos de Um Diretorio
//lista arquivos
TableDeleteAll(TABLE_lista_arquivos)
s_arquivos_todos is string=fListFile(SAI_DIRETORIO+"*.*")
s_arquivo_individual is string=""
FOR EACH STRING s_arquivo_individual OF s_arquivos_todos SEPARATED BY CR
s_nome_arquivo is string=fExtractPath(s_arquivo_individual,fFileName+fExtension)
s_tamanho_arquivo is string=fSize(SAI_DIRETORIO+s_nome_arquivo)
dS_data_arquivo is Date=fDate(SAI_DIRETORIO+s_nome_arquivo)
hS_hora_arquivo is Time=fTime(SAI_DIRETORIO+s_nome_arquivo)
TableAddLine(TABLE_lista_arquivos,s_nome_arquivo,s_tamanho_arquivo,dS_data_arquivo,hS_hora_arquivo)
END
TableSort(TABLE_lista_arquivos,"-TABLE_lista_arquivos.COL_Data","-TABLE_lista_arquivos.COL_Hora")
//pesquisa diretorio
sRépertoire_ is string
sRépertoire_ = fSelectDir("", "")
SAI_DIRETORIO=sRépertoire_
//Blog com video e Exemplo
http://windevdesenvolvimento.blogspot.com.br/2016/02/curso-windev-arquivos-001-listar.html
De matos AMARILDO
09 Feb. 2016
Mostrar os Arquivos de Um Diretorio
PROCEDURE arquivo_mostra_local()
//leio o conteudo do diretorio e preencho tabela
TableDeleteAll(TABLE_local)
s_arquivo_individual is string=""
s_arquivo_todos is string=fListFile(ftp_conf.endereco_local+"*.*") // mostra arquivos diretorio
s_nome_arquivo is string=""
s_tamanho_arquivo is string=""
d_data_arquivo is Date=""
h_hora_arquivo is Time=""
_atributos_arquivo is string=""

FOR EACH STRING s_arquivo_individual OF s_arquivo_todos SEPARATED BY CR
s_nome_arquivo=fExtractPath(s_arquivo_individual,fFileName+fExtension)
s_tamanho_arquivo=fSize(ftp_conf.endereco_local+s_nome_arquivo)
d_data_arquivo=fDate(ftp_conf.endereco_local+s_nome_arquivo)
h_hora_arquivo=fTime(ftp_conf.endereco_local+s_nome_arquivo)
TableAddLine(TABLE_local,s_nome_arquivo,s_tamanho_arquivo,d_data_arquivo,h_hora_arquivo)
// outras informacoes uteis
_atributos_arquivo=fAttribut(ftp_conf.endereco_local+s_nome_arquivo) // atribuito arquivo
Info(fExtractPath(s_arquivo_individual,fDisque)) // drive
Info(fExtractPath(s_arquivo_individual,fExtension)) // extensao
Info(fExtractPath(s_arquivo_individual,fFichier)) // nome arquivo
Info(fExtractPath(s_arquivo_individual,fRépertoire)) // diretorio
Info(fExtractPath(s_arquivo_individual, fRépertoire)) // diretorio
END

De matos AMARILDO
02 Jan. 2016