Cry about...
Delphi Programming with WinInet


Example of FtpFindFirstFile and InternetFindNextFile


The following code fragment shows how to use FtpFindFirstFile together with InternetFindNextFile to list the contents of the current folder. This example simply returns the names of all the files and folders concatenated together into a string.

function ListCurrentDirectory(handle: HInternet): string;
var
  hSearch: HINTERNET;
  findData: WIN32_FIND_DATA;
begin
  hSearch := FtpFindFirstFile(handle,nil,findData,0,0);
  if hSearch = nil then
  begin
    // Something has gone wrong!
    // Perhaps we've been disconnected?
    result := '';
  end
  else
  begin
    //--------------------------------
    // Loop reading directory entries.
    //--------------------------------
    result := '';
    repeat
      result := result + findData.cFileName + ' ';
    until not InternetFindNextFile(hSearch,@findData);
    InternetCloseHandle(hSearch);
  end;
end;

These notes are believed to be correct for Delphi 6, but may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.