Recent

Author Topic: Return the contents of a folder as a string?  (Read 4537 times)

captian jaster

  • Guest
Return the contents of a folder as a string?
« on: April 10, 2010, 08:05:38 pm »
How would i get the contents of a folder and return as a writable string?

Bart

  • Hero Member
  • *****
  • Posts: 5349
    • Bart en Mariska's Webstek
Re: Return the contents of a folder as a string?
« Reply #1 on: April 10, 2010, 11:05:27 pm »
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

  • Sr. Member
  • ****
  • Posts: 346
Re: Return the contents of a folder as a string?
« Reply #2 on: April 11, 2010, 07:12:42 am »
You can find an example at http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst.

Thys code don't show hided directory:
Code: [Select]
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;

For search also hided directories, i use
Code: [Select]
  if FindFirst('*', faAnyFile, searchResult) = 0 then
instead of
  if FindFirst('*', faDirectory, searchResult) = 0 then
Hi, Mario

 

TinyPortal © 2005-2018