|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Counting number of files in a directory
Hi people. Probably a simple thing. I need to count the number of files in a directory and then output that to a text file. I can do the text file part. Not sure about the counting the files. Please help.
|
|
#2
|
||||
|
||||
|
You can use FindFirst, FindNext and FindClose to iterate through a directory. You can count the files while iterating thru the dir. See the example for FindFirst in the help file for how to use these functions.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
??
I have looked at the helpfiles and it isnt very clear. The example is checking file attributes. Please will you give me abit more details. Thanks
|
|
#4
|
||||
|
||||
|
The following code evaluates all the files in C:\*.* and excludes directories from that file count.
Code:
function TForm1.CountFiles : integer;
var
Rec : TSearchRec;
nFileCount : integer;
foo : string;
begin
nFileCount := 0;
if FindFirst('C:\*.*', faAnyFile, Rec) = 0 then
begin
repeat
// Exclude directories from the list of files.
if ((Rec.Attr and faDirectory) <> faDirectory) then
Inc(nFileCount);
until FindNext(Rec) <> 0;
FindClose(Rec);
end;
Result := nFileCount;
end;
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Counting number of files in a directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|