Для копирования путь к коп.файлу берется с
listview1.items[i].caption
путь указан - но так как надо указать еще и название файла я беру ее с
li.Subitems[1]
но почему то после первой удачной копировании оно мне выдает ощибку
Код:
var
SrcFile, DestFile: file;
BytesRead, BytesWritten, TotalRead: Integer;
Buffer: array[1..500] of byte;
i, FSize: Integer;
begin
if listview1.Items.Count=0 then exit;
for i:=0 to listview1.Items.Count +1 do
begin
prbCopy.Position:=0;
AssignFile(SrcFile, listview1.Items[i].Caption);
AssignFile(DestFile, 'C:\'+li.SubItems[1]);//в li.SubItems[1] путь не указан
//только имя файла.расчирения
Reset(SrcFile, 1);
try
Rewrite(DestFile, 1);
try
try
TotalRead := 0;
FSize := FileSize(SrcFile);
repeat
BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
if BytesRead > 0 then
begin
BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
if BytesRead <> BytesWritten then
raise Exception.Create('Error copying file')
else
begin
TotalRead := TotalRead + BytesRead;
prbCopy.Position := Trunc(TotalRead / Fsize) * 100;//prbCopy- прогрессбар
prbCopy.Update;
end;
end
until BytesRead = 0;
except
Erase(DestFile);
raise;
end;
finally
CloseFile(DestFile);
end;
finally
CloseFile(SrcFile);
listview1.Items[i].Delete;//удаляем то что уже скопировали
end;
end;
Почему оно выдает мне ощибку - в чем трабла??