Solved

list files (dos like dir call)

Posted on 1997-07-20
2
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 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