Solved

listing directory

Posted on 1998-12-04
3
169 Views
Last Modified: 2010-04-04
How can i retrieve the list of files in some directory
(c:\temp for example) using functions(Win32API), not
DELPHI VCL (TFileListBox, TDirectoryListBox, etc)
0
Comment
Question by:jpenev3
[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
3 Comments
 

Expert Comment

by:Aleq
ID: 1349288
FindFirst, FindNext uses win32api, or at least I think so ....
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 70 total points
ID: 1349289
jpenev3

Aleq has the right Idea there, use this code on a button click or so, it uses TSearchRec and Findfirst etc...

var
  sr : TSearchRec;
  R : integer;
begin
   R := Sysutils.FindFirst('C:\Temp\*.*', faAnyFile, sr);
   while R = 0 do
   begin
     Memo1.Lines.Add(sr.FindData.cFileName);
     {if sr.FindData.cAlternateFileName <> '' then
       Memo1.Lines.Add(sr.FindData.cAlternateFileName) else}
       //Memo1.Lines.Add(sr.FindData.cFileName);
     R := Sysutils.FindNext(sr);
   end;
   Sysutils.FindClose(sr);
end;

the other options are:

faReadOnly //Read-only files
faHidden //Hidden files
faSysFile //System files
faVolumeID //Volume ID files
faDirectory //Directory files
faArchive       //Archive files
faAnyFile       //Any file

Later
BoRiS
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1349290
Here's a simple way:

var
  list: TStringList;
  ...

procedure ...
var
  sr: TSearchRec;
begin
  if FindFirst(Directory + '*.*', faAnyFile, sr) = 0 then
  repeat
    list.Add(sr.Name);
  until FindNext(sr) <> 0;
  FindClose(sr);
end;
end;

/// John  
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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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