Subj : Directory Listing
To : All
From : Robert Wolfe
Date : Thu Nov 27 2014 06:13 am
Hello everybody.
I am trying to get a listing of files in the currently logged directory and
output those to a text file. However, I cannot seem to figure out how to do
this with the FindFirst() and FindNext() functions in FreePascal. The example
I tried to base my own code on is as follows:
Var
Path : String;
SR : TSearchRec;
DirList : TStrings;
begin
if OpenPictureDialog1.Execute then
begin
Path:=ExtractFileDir(OpenPictureDialog1.FileName); //Get the path of the
selected file
DirList:=TStringList.Create;
try
if FindFirst('*.*', faArchive, SR) = 0 then
begin
repeat
DirList.Add(SR.Name); //Fill the list
until FindNext(SR) <> 0;
FindClose(SR);
end;
//do your stuff
finally
DirList.Free;
end;
end;
end;
Unfortunately, I was not able to get my example (which follows) to work:
Procedure GenDirFile ;
Var SR: TSearchRec ;
DirList: TStrings;
Path: String;
DirFile: Text;
Begin ;
Assign(DirFile, 'directory.lst') ;
Rewrite(DirFile) ;
DirList := TStringsList.Create;
if FindFirst('*.zip', faArchive, SR) = 0 then
begin
repeat
WriteLn(DirFile, SR.Name);
until FindNext(SR) <> 0;
FindClose(SR);
end;
Close(DirFile);
End ;
Is there something I am doing wrong here? Any help anyone can give would be
greatly appreciated.