📄 ufilecopy.~pas
字号:
unit uFileCopy;
interface
const
BUFFER_SIZE = 1024*1024*4;
function myFileCopy( AstrSrcFileName : String;
AstrDestFileName : String ) : Boolean; forward;
function myFileCopy1( AstrSrcFileName : String;
AstrheFileName :string;
AstrDestFileName : String ) : Boolean; forward;
function myFileCopy2( AstrSrcFileName : String;
AstrheFileName :string;
AstrDestFileName : String ) : Boolean; forward;
function myFileCopy3( AstrSrcFileName : String;
AstrDestFileName : String ) : Boolean; forward;
implementation
Uses
Dialogs, SysUtils;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
function myFileCopy( AstrSrcFileName : String;
AstrDestFileName : String ) : Boolean;
var
hSrcFile, hDestFile : Integer;
nFileReaded : Integer;
//Buffer : array[0..BUFFER_SIZE] of char;
pBuffer : PChar;
begin
Result := False;
pBuffer := nil;
try
GetMem( pBuffer, BUFFER_SIZE );
hSrcFile := FileOpen( AstrSrcFileName, fmOpenRead );
if( hSrcFile <> -1 ) then
begin
hDestFile := FileOpen( AstrDestFileName, fmOpenWrite );
if( hDestFile = -1 ) then
begin
hDestFile := FileCreate( AstrDestFileName );
end;
if( hDestFile <> -1 ) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^, BUFFER_SIZE );
while( nFileReaded > 0 ) do
begin
FileWrite( hDestFile, pBuffer^, nFileReaded );
nFileReaded := FileRead( hSrcFile, pBuffer^, BUFFER_SIZE );
end;
FileClose( hDestFile );
Result := True;
end;
FileClose( hSrcFile );
end;
finally
if( pBuffer <> nil ) then
FreeMem( pBuffer );
end;
end;
function myFileCopy1( AstrSrcFileName : String;
AstrheFileName :string;
AstrDestFileName : String ) : Boolean;
var
hSrcFile, hDestFile,hhefile : Integer;
nFileReaded : Integer;
//Buffer : array[0..BUFFER_SIZE] of char;
pBuffer : PChar;
begin
Result := False;
pBuffer := nil;
try
GetMem( pBuffer, BUFFER_SIZE );
hSrcFile := FileOpen( AstrSrcFileName, fmOpenRead );
hheFile := FileOpen( AstrheFileName, fmOpenRead );
if( ( hSrcFile <> -1 ) and ( hheFile <> -1 ) )then
begin
hDestFile := FileOpen( AstrDestFileName, fmOpenWrite );
if( hDestFile = -1 ) then
begin
hDestFile := FileCreate( AstrDestFileName );
end;
if( hDestFile <> -1 ) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^, BUFFER_SIZE );
while( nFileReaded > 0 ) do
begin
FileWrite( hDestFile, pBuffer^, nFileReaded );
nFileReaded := FileRead( hSrcFile, pBuffer^, BUFFER_SIZE );
end;
// Result := True;
end;
if( hDestFile <> -1 ) then
begin
nFileReaded := FileRead( hheFile, pBuffer^, BUFFER_SIZE );
while( nFileReaded > 0 ) do
begin
FileWrite( hDestFile, pBuffer^, nFileReaded );
nFileReaded := FileRead( hheFile, pBuffer^, BUFFER_SIZE );
end;
FileClose( hDestFile );
Result := True;
end;
end;
if( hSrcFile <> - 1 ) then
FileClose( hSrcFile );
if( hhefile <> -1 ) then
FileClose( hhefile );
finally
if( pBuffer <> nil ) then
FreeMem( pBuffer );
end;
end;
{
function myFileCopy2( AstrSrcFileName : String;
AstrheFileName :string;
AstrDestFileName : String ) : Boolean;
var
hSrcFile, hDestFile ,hheFile: Integer;
nFileReaded : Integer;
//Buffer : array[0..BUFFER_SIZE] of char;
pBuffer : PChar;
begin
Result := False;
pBuffer := nil;
try
GetMem( pBuffer, BUFFER_SIZE );
hSrcFile := FileOpen( AstrSrcFileName, fmOpenRead );
hheFile := FileOpen( AstrheFileName, fmOpenRead );
if( hSrcFile <> -1 ) then
begin
hDestFile := FileOpen( AstrDestFileName, fmOpenWrite );
if( hDestFile = -1 ) then
begin
hDestFile := FileCreate( AstrDestFileName );
end;
if (hsrcfile<> -1) then
begin
hhefile:=fileopen(AstrhefileName,fmOpenWrite);
if(hheFile=-1) then
begin
hhefile:=FileCreate(AstrhefileName);
end;
end;
if( hDestFile <> -1 ) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^,5 );
if( nFileReaded > 0) then
begin
FileWrite( hDestFile, pBuffer^, nFileReaded );
nFileReaded := FileRead( hSrcFile, pBuffer^, 5 );
end;
if( hheFile <>-1) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^, (BUFFER_SIZE) );
if( nFileReaded > 0) then
begin
FileWrite( hheFile, pBuffer^,nFileReaded );
nFileReaded := FileRead( hSrcFile, pBuffer^, (BUFFER_SIZE) );
end;
FileClose( hDestFile );
FileClose(hheFile);
Result := True;
end;
end;
end;
if( hSrcFile <> - 1 ) then
FileClose( hSrcFile );
// if( hhefile <> -1 ) then
// FileClose( hhefile );
finally
if( pBuffer <> nil ) then
FreeMem( pBuffer );
end;
end;
}
function myFileCopy2( AstrSrcFileName : String;
AstrheFileName :string;
AstrDestFileName : String ) : Boolean;
var
hSrcFile, hDestFile ,hheFile: Integer;
nFileReaded : Integer;
//Buffer : array[0..BUFFER_SIZE] of char;
pBuffer : PChar;
begin
Result := False;
pBuffer := nil;
try
GetMem( pBuffer, BUFFER_SIZE );
hSrcFile := FileOpen( AstrSrcFileName, fmOpenRead );
if( hSrcFile <> -1 ) then
begin
hhefile:=fileopen(AstrhefileName,fmOpenWrite);
if(hheFile=-1) then
begin
hhefile:=FileCreate(AstrhefileName);
end;
hDestFile := FileOpen( AstrDestFileName, fmOpenWrite );
if( hDestFile = -1 ) then
begin
hDestFile := FileCreate( AstrDestFileName );
end;
if( hhefile <> -1 ) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^,5 );
if( nFileReaded > 0) then
begin
FileWrite( hhefile, pBuffer^, nFileReaded );
end;
if( hDestFile <>-1) then
begin
nFileReaded := FileRead( hSrcFile, pBuffer^, (BUFFER_SIZE) );
if( nFileReaded > 0) then
begin
FileWrite( hDestFile, pBuffer^,nFileReaded );
end;
FileClose( hDestFile );
FileClose(hheFile);
Result := True;
end;
end;
end;
if( hSrcFile <> - 1 ) then
FileClose( hSrcFile );
//if( hhefile <> -1 ) then
//FileClose( hhefile );
finally
if( pBuffer <> nil ) then
FreeMem( pBuffer );
end;
end;
function myFileCopy3( AstrSrcFileName : String;
AstrDestFileName : String ) : Boolean;
var
hSrcFile, hDestFile : Integer;
nFileReaded : Integer;
Buffer : array[0..100] of char;
i:integer;
nReadCount : integer;
t:char;
begin
try
hSrcFile := FileOpen( AstrSrcFileName, fmOpenRead );
if( hSrcFile <> -1 ) then
begin
hDestFile := FileOpen( AstrDestFileName, fmOpenWrite );
if( hDestFile = -1 ) then
hDestFile := FileCreate( AstrDestFileName );
nReadCount:=0;
//while(nfilereaded>-1) do
//begin
nFileReaded := FileRead( hSrcFile,Buffer[nReadCount],100 );
//inc(nReadCount);
//end;
{if(hDestFile<>-1) then
i:=FileSeek(hSrcFile,0,2);
end; FileSeek(hSrcFile,0,0);
Setlength(Buffer,i+1);
nFileReaded:=FileRead(hSrcFile,BUffer[0],i+1);}
begin
for i:=0 to nFileReaded-1 do
begin
t:=buffer[i];
buffer[i]:=buffer[nFileReaded-1-i];
buffer[nFileReaded-1-i]:=t;
{for i:=nFileReaded-1 downto 0 do
begin
FileWrite( hDestFile, Buffer[i],1 );
end; }
end;
FileWrite( hDestFile, Buffer[0],nFileReaded);
FileClose( hDestFile );
end;
FileClose( hSrcFile );
end;
finally
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -