![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как ;в программе выполнить копирование файла?
MaGG © (2002-04-27 12:48:00)Как в программе выполнить копирование файла?
MVVD (2002-04-27 13:43:00) [21]procedure CopyFile(const FileName, DestName: string);
var
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
if DMod.HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
if Destination[Len] = "\" then
Destination := Destination + ExtractFileName(FileName) { ...clone file name }
else
Destination := Destination + "\" + ExtractFileName(FileName); { ...clone file name }
end;
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyNone); { open source file }
if Source < 0 then raise EFOpenError.CreateFmt(SFOpenError, [FileName]);
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
if Dest < 0 then raise EFCreateError.CreateFmt(SFCreateError, [Destination]);
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;
Johnmen (2002-04-27 13:43:00) [22]>Vovchik © (27.04.02 13:34)
Пусть дети начинают с малого...
И не надо такого апломба...
MVVD (2002-04-27 13:42:00) [23]procedure CopyFile(const FileName, DestName: string);
var
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
if DMod.HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
if Destination[Len] = "\" then
Destination := Destination + ExtractFileName(FileName) { ...clone file name }
else
Destination := Destination + "\" + ExtractFileName(FileName); { ...clone file name }
end;
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyNone); { open source file }
if Source < 0 then raise EFOpenError.CreateFmt(SFOpenError, [FileName]);
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
if Dest < 0 then raise EFCreateError.CreateFmt(SFCreateError, [Destination]);
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;
Vovchik (2002-04-27 13:34:00) [24]> Johnmen
Я бы Вам самому посоветовал учить матчасть!
Не учите детей неправильным подходам.
> MaGG
Ничего лучше SHFileOperation ещё никто не придумал. Она работает гораздо быстрее, чем CopyFile. См. SDK. Если нет нормального, то в поставке дельфи есть некая старая версия.
Johnmen (2002-04-27 13:27:00) [25]DeleteFile
смотри хелп по Win"довым ф-ям....
MaGG (2002-04-27 13:15:00) [26]ПОМОГИТЕ! Ну нету у меня книжки,
а в хелпе не нашел.
А еще как удалить файл?
Johnmen (2002-04-27 13:01:00) [27]CopyFile
учите матчасть !