PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → How to retrieve the total number of items in a folder ?
How to retrieve the total number of items in a folder ?
Iniciado por software, 19,ene. 2016 16:24 - 2 respuestas
Miembro registrado
27 mensajes
Publicado el 19,enero 2016 - 16:24
Hi,

Example : How to find the total number of items in a windows folder ex. c:\temp by means of programming in windev ?

I tried already fListFile, fListDirectory and fDir but can't find an answer to my question.

Kind regards,

Eric
Publicado el 20,enero 2016 - 11:05
Hi,

One approach is to list all the files and then count the number os CR (that is the character that separates the files).

You can try the following code:

// If you want the number of FILES
sResFileList is string = fListFile("C:\TEMP\*.*",frRecursive + frInterruptible)
nNumberofFiles is int = 0
IF sResFileList <> "" THEN
nNumberofFiles = StringCount(sResFileList,CR)>0?StringCount(sResFileList,CR)+1 ELSE 1
END


// If you want the number of DIRECTORIES
sResFileDirect is string = fListDirectory("C:\TEMP",frRecursive + frInterruptible)
nNumberofDirectories is int = 0
IF sResFileDirect <> "" THEN
nNumberofDirectories = StringCount(sResFileDirect,CR)>0?StringCount(sResFileDirect,CR)+1 ELSE 1
END

Hope it helps!

Regards,

Bruno

PS: if expected a high number of items then you should use fdir because is faster;
Miembro registrado
27 mensajes
Publicado el 21,enero 2016 - 16:50
Thank you Bruno, i worked with FDir and it works fine !

ex.

// Declare the variable
ResFile is string
i is int = 0
ResFile = fDir("T:\Eric\in\*.*", frFile)
WHILE ResFile <> ""
i++
ResFile = fDir("", frFile)
END
Info("There are " + i + " itemspresent in the folder")