How do I get the list of files in a folder?

You need to extract all the possible information from a folder but don't know where to start? Look no further, PPL offers a great flexibility when it comes to using Windows API functions.

The following code will open up the console and output all the files that are contained in the C:\Program Files\PPL\Runtime\ folder.

A new list item is created to store all the filenames.

Imagine the possibilities... The fd$ structure contains important information about each file scanned, like: File attributes, Creation Time, Last Access Time, Last Write Time, File Size and Filename.

#include "console"
func WinMain
InitConsole;
ShowConsole;

List(files$);
  struct(fd$, WIN32_FIND_DATA);
i$ = FindFirstFile("c:\\Program Files\\PPL\\*.*", &fd$);
if (i$ != INVALID_HANDLE_VALUE)
repeat
Add(files$, char(fd.cFilename$));
until (FindNextFile(i$, &fd$) == false);
FindClose(i$);
end;

ForEach(Files$);
Writeln(Files$);
end;

return (true);
end;