You are on page 1of 1

procedure TForm1.

Button1Click(Sender: TObject);
var
F: File;
i, filehandle: Integer;
begin
for i := 0 to (FileListBox1.Items.Count - 1) do begin
try
if FileListBox1.Selected[i] then
begin
if not FileExists(FileListBox1.Items.Strings[i]) then
begin
MessageDlg('File: ' + FileListBox1.Items.Strings[i] +
' not found', mtError, [mbOk], 0);
Continue;
end;
filehandle:= FileOpen(FileListBox1.Items.Strings[i], fmOpenWrite);
if (filehandle = -1) then
begin
MessageDlg('File: ' + FileListBox1.Items.Strings[i] +
' cannot be opened with access mode fmOpenWrite.', mtError,
[mbOk], 0);
Continue;
end
else
FileClose(filehandle);

AssignFile(F, FileListBox1.Items.Strings[i]);
Reset(F, 1);
ListBox1.Items.Add(
FileListBox1.Items.Strings[i] + ': ' + IntToStr(FileSize(F)));
CloseFile(F);
end;
finally
{ Do something here. }
end;
end;
end;

You might also like