natie_49
Messages postés5Date d'inscriptionmardi 17 mai 2005StatutMembreDernière intervention 3 juin 2005
-
17 mai 2005 à 16:59
natie_49
Messages postés5Date d'inscriptionmardi 17 mai 2005StatutMembreDernière intervention 3 juin 2005
-
19 mai 2005 à 09:12
La fonction ci-dessous ne fonctionne pas correctement, aidez moi svp!!
Merci davance.
function Copiefichier(srctmp, dsttmp : TRes) : Boolean; export;
var
Copybuffer : Pointer;
BytesCopied : Longint;
Source, Dest : Integer;
D_Dir : TRes;
FBufferSize : Integer;
begin
// affectation du résultat par défaut
result:=True;
// si le fichier source existe et la destination non nulle
if (fileexists(srctmp)) and (dsttmp<>'') then
begin
// Si le répertoire de destinantion n'existe pas on le crée
D_dir := ExtractFilePath(dsttmp);
if not DirectoryExists(D_Dir) then ForceDirectories(D_Dir);
// On alloue la mémoire au buffer de copie de fichier
GetMem(Copybuffer, FBufferSize);
try
// On ouvre le fichier
source := FileOpen(srctmp, fmShareDenyNone);
if Source<0 then begin result:=false;end;
try
// Création du fichier de destination
Dest := FileCreate(dsttmp);
if Dest<0 then begin result:=false;end;
try
// On copie tant que l'on a encore quelque chose à copier
repeat
BytesCopied := FileRead(Source, Copybuffer^, FBufferSize);
if BytesCopied>0 then
begin
// Ecriture du Buffer
if not (FileWrite(Dest, Copybuffer^, BytesCopied)>0) then
begin result:=false;end;
end;
until BytesCopied<FBufferSize;
FileSetDate(Dest,FileGetDate(Source));
finally
// Fermeture du fichier destination
FileClose(Dest);
end;
finally
// Fermeture du fichier source
FileClose(Source);
end;
finally
// Libération de la mémoire allouée au Buffer
freemem(Copybuffer, FBufferSize);
end;
end;
end;
natie_49
Messages postés5Date d'inscriptionmardi 17 mai 2005StatutMembreDernière intervention 3 juin 2005 19 mai 2005 à 09:12
function Copiefichier(srctmp, dsttmp : TRes) : Boolean; export;
var
Copybuffer : Pointer;
BytesCopied : Longint;
Source, Dest : Integer;
D_Dir : TRes;
FBufferSize : word;
begin
FBufferSize := 1024;
// affectation du résultat par défaut
result:=False;
// si le fichier source existe et la destination non nulle
if (fileexists(srctmp)) and (dsttmp<>'') then
begin
// Si le répertoire de destinantion n'existe pas on le crée
D_dir := ExtractFilePath(dsttmp);
if not DirectoryExists(D_Dir) then ForceDirectories(D_Dir);
// On alloue la mémoire au buffer de copie de fichier
GetMem(Copybuffer, FBufferSize);
try
// On ouvre le fichier
Source := FileOpen(srctmp, fmShareDenyNone);
if Source<0 then begin result:=false;end;
try
// Création du fichier de destination
Dest := FileCreate(dsttmp);
if Dest<0 then begin result:=false;end;
try
// On copie tant que l'on a encore quelque chose à copier
repeat
BytesCopied := FileRead(Source, Copybuffer^, FBufferSize);
if BytesCopied>0 then
begin
// Ecriture du Buffer
if not (FileWrite(Dest, Copybuffer^, BytesCopied)>0) then
begin result:=false;end;
end;
until BytesCopied<FBufferSize;
FileSetDate(Dest,FileGetDate(Source));
result:=true;
finally
// Fermeture du fichier destination
FileClose(Dest);
end;
finally
// Fermeture du fichier source
FileClose(Source);
end;
finally
// Libération de la mémoire allouée au Buffer
freemem(Copybuffer, FBufferSize);
end;
end;
end;