Solved

listing directory

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 102
select query - oracle 16 100
LAN or WAN ? 11 90
Drag & Drop... Data from one grid to another 2 10
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

806 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