Solved

list files (dos like dir call)

Posted on 1997-07-20
2
164 Views
Last Modified: 2010-04-04
how can I make a dos like dir call in delphi and store the info in a stringlist...ie given a string like 'c:\windows\files', how can I get the filenames from this directory and store them in a stringlist....please keep the answer simple (if possible). An example would be greatly appreciated.

Thanks in advance.
0
Comment
Question by:rafy
2 Comments
 
LVL 4

Accepted Solution

by:
erajoj earned 70 total points
ID: 1339363
Do like this:

procedure DirToStrList(
  Dir: string; List: TStrings; FilesOnly: Boolean);
var
  SearchRec: TSearchRec;
begin
  List.Clear;                        // Just in case
  { Are there any files? }
  if FindFirst(Dir+'\*.*', faAnyFile, SearchRec)=0
  then repeat
    { Do we want dirs? }
    if (SearchRec.Attr<>faDirectory) or not FilesOnly
    then List.Add(SearchRec.Name); // Add to list
  until FindNext(SearchRec)<>0;    // Loop through all
  SysUtils.FindClose(SearchRec);   // Close to release memory
end;

Call like this:
  ( Root dir into ListBox1.Items, files only )
  DirToStrList('C:\', ListBox1.Items, True);

  ( "c:\windows\files" into Memo1.Lines, dirs allowed )
  DirToStrList('c:\windows\files', Memo1.Lines, False);

  ( "c:\windows\files" into new stringlist, files only )
  var
    Dir: TStringList;
  begin  
    Dir := TStringList.Create;
    DirToStrList('c:\windows\files', Dir, True);
    ...
    ...
    Dir.Free; // No need for this anymore!

---
Hope this helps!

/// John

0
 

Author Comment

by:rafy
ID: 1339364
Perfect!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TServerSocket - file via sendbuf or Text via sendtext ? 1 76
Multiple image collision 13 87
Delphi: sending SMS on android platform 1 61
shape, triangle, dbctrlgrid 3 31
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question