File list

I have file names in TXT file (1 name = 1 line). Now I need to compare file list in TXT with files in C:\WINDOWS and write to Memo names of files, which are new or added.
Delphi 3
Step by step, please...
pipigrilAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ckanetaConnect With a Mentor Commented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes,
  Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, FileCtrl;

type
 TForm1 = class(TForm)
  fils: TFileListBox;
  Btn: TButton;
  Memo1: TMemo;
  Memo2: TMemo;
  procedure FormCreate(Sender: TObject);
  procedure BtnClick(Sender: TObject);
  private
   procedure loadfl;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
{------------------------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
 begin
  fils.Directory:='c:\windows';
  memo1.lines.clear; memo2.lines.clear;
  loadfl;
 end;
procedure TForm1.loadfl;
var ifl:Textfile; tmp:string;
 begin
  assignfile(ifl,ExtractFilepath(application.exename)+'fillst.txt'); reset(ifl);
  while not EOF(ifl) do begin
   readln(ifl,tmp);
   memo2.Lines.Add(tmp);
  end;
  closefile(ifl);
 end;
{------------------------------------------------------------------------------}
procedure TForm1.BtnClick(Sender: TObject);
var c:integer;
 begin
  for c:= 0 to fils.Items.count-1 do begin
   if memo2.Lines.IndexOf(fils.items[c]) = -1 then memo1.lines.add(fils.items[c]);
  end;
 end;

end.
0
 
kretzschmarCommented:
hi pipigril,

read the textfile in a tstringlist
read the filenames in a tstringlist (findfirst/findnext)

now go through the file-Tstringlist and lookup in the text-Tstringlist with the indexof-method

if the result < 0 then add the filename to your memo

meikl
0
 
edeyCommented:
or you could call command.com to pipe a dir c:\windows\*.* to a text file & load that, though the findFirst/findNext method would prob. be cleaner.

Gl
Mike
0
 
ckanetaCommented:
or you could use a TFileListBox compnent, point it at the appropriate
directory, and read a line of the file
and compare that to the lines in the component
0
All Courses

From novice to tech pro — start learning today.