home bbs files messages ]

Just a sample of the Echomail archive

<< oldest | < older | list | newer > | newest >> ]

 Message 201 
 Robert Wolfe to All 
 Directory Listing 
 27 Nov 14 06:13:02 
 
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.

Robert

--- GoldED+/EMX 1.1.5-b20110223
 * Origin: Wolfe's OS/2 BBS * Memphis TN * os2.winserver.us (1:116/18)

<< oldest | < older | list | newer > | newest >> ]

(c) 1994,  bbs@darkrealms.ca