Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

list files (dos like dir call)

Posted on 1997-07-20
2
Medium Priority
?
178 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 280 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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