Solved

listing directory

Posted on 1998-12-04
3
163 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i remove white background in node inside virtual TVirtualStringTree? 12 92
indy tidtcpclient threading issue 8 63
PDF library for Delphi 2 107
Delphi 2 51
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now