Forum > General

Return the contents of a folder as a string?

(1/1)

captian jaster:
How would i get the contents of a folder and return as a writable string?

Bart:
Take a look at (and read up on) the FindFirst() FindNext() (and FindClose) functions.

You can find an example at http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst.

Bart

bonmario:

--- Quote from: Bart on April 10, 2010, 11:05:27 pm ---You can find an example at http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst.

--- End quote ---

Thys code don't show hided directory:

--- Code: ---Example code : Find all directories above and including the current one
var
  searchResult : TSearchRec;

begin
  // Try to find directories above the current directory
  SetCurrentDir('..');

  if FindFirst('*', faDirectory, searchResult) = 0 then
  begin
    repeat
      // Only show directories
      if (searchResult.attr and faDirectory) = faDirectory
      then ShowMessage('Directory = '+searchResult.Name);
    until FindNext(searchResult) <> 0;

    // Must free up resources used by these successful finds
    FindClose(searchResult);
  end;
end;
--- End code ---

For search also hided directories, i use

--- Code: ---  if FindFirst('*', faAnyFile, searchResult) = 0 then
instead of
  if FindFirst('*', faDirectory, searchResult) = 0 then

--- End code ---
Hi, Mario

Navigation

[0] Message Index

Go to full version