'CopyFile' og 'CopyFileEx' - Error: 2 ved GetLastError ???
CopyFile vil ikke kopiere filer ??? - Se følgende, evt. hele proceduren i context nederst !Denne kode er i en unit, uden TForm
<Snip>
FOR idx := 0 TO NumOfAttFiles-1 DO
Begin
SourceFile := OutAttFileNames[idx]; // => er en TStrings fra en TOpenDialog på en Form
//TargetFile := OutAttachmentSavePath + '*.*';
TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
----------------------------------------------------------------------------
--------------------------------------------------------------------------->
>>>>>>
//CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
IF not
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
nter,pCancel,dwCopyFlags) then
Log('Copy file failed, error ' + IntToStr (GetLastError));
<snip>
Mvh
Alex
----------------------------------------------------->>>
Det er meningen, at nogle filer, som udpeges i anden unit, via TOpenDialog,
giver en "TStrings" som jeg itererer gennem, og vil så kopiere fra den
fil-navn, til en lokal temp folder under Prog-run-time.
Kompilerer og kører fint, men ingen filer kopieres ???
----------------------
Procedure
TTeleEmail.PackReplyEmlAttachments(SubFolder,EmlFileNameAndExt:String;VAR
ChilkatEmailObj:ChilkatEmail;OutAttFileNames:TStrings;VAR
NumOfAttFiles:Byte);
VAR
idx:Byte;
OutAttachmentSavePath,NewTempAttachmentDir,SourceFile,TargetFile:WideString;
pCancel,dummyPointer:Pointer;
dwCopyFlags:Word;
debugDummy1:String;
searchResult:TSearchRec;
sRes:Integer;
resCopyFile:LongBool;
Begin
idx := 0;
NewTempAttachmentDir := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder;
NumOfAttFiles := OutAttFileNames.Count;
ChilkatEmailObj.Mailer := DefaultXMailerTag;
try
MkDir(NewTempAttachmentDir);
if IOResult <> 0 then
Log('Cannot create directory ... - '+NewTempAttachmentDir)
else
Log('New directory created ... - '+NewTempAttachmentDir);
except
Log('Cannot create directory ... - '+NewTempAttachmentDir);
end;
OutAttachmentSavePath := CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + OutAttachmentsSubFolder + '\';
//pCancel:=Addr(Cancel);
dwCopyFlags := COPY_FILE_RESTARTABLE;
IF (NumOfAttFiles > 0) THEN
try
// Copy file(s)
//CopyFileEx(SourceFile,TargetFile,NULL,NULL,pCancel,dwCopyFlags);
FOR idx := 0 TO NumOfAttFiles-1 DO
Begin
SourceFile := OutAttFileNames[idx];
//TargetFile := OutAttachmentSavePath + '*.*';
TargetFile := OutAttachmentSavePath + ExtractFileName(SourceFile);
----------------------------------------------------------------------------
--------------------------------------------------------------------------->
>>>>>>
//CopyFile(PChar(SourceFile),PChar(TargetFile),FALSE);
IF not
Windows.CopyFileEx(PChar(SourceFile),PChar(TargetFile),dummyPointer,dummyPoi
nter,pCancel,dwCopyFlags) then
Log('Copy file failed, error ' + IntToStr (GetLastError));
----------------------------------------------------------------------------
--------------------------------------------------------------------------<<
<<<<<
debugDummy1 := 'pause';
end;
except
// Handles copy error(s)
Log('TeleEmail01.PackReplyEmlAttachments-> Error: OutAttachmentFile
could was not copied correctly/not found');
end; // try .. except
sRes := FindFirst(OutAttachmentSavePath + '*.*',faAnyFile,searchResult);
IF sRes = 0 THEN // = = Result was success, files found
try // try (2)
While sRes = 0 DO
Begin
//IF (searchResult.Attr and faDirectory) <> faDirectory THEN
Begin
if (searchResult.Name <> '') THEN
ChilkatEmailObj.AddFileAttachment(OutAttachmentSavePath +
searchResult.Name);
end;
sRes := FindNext(searchResult);
end;
//except
//Handle exception
finally
FindClose(searchResult);
end; // end ... try (2)
ChilkatEmailObj.SaveEml(CurrentDir + '\' + TempFileFolder + '\' +
SubFolder + '\' + ReplyEmailNameInZip);
end;
-------------------------->>>
Her kaldes proceduren med relevante parametre
function TTeleEmail.AddAttToReplyEmail(ContactRespID:String;VAR
OutAttachmentFileNames:TStrings):Integer;
VAR
NumOfAttachments:Byte;
Begin
NumOfAttachments := 0;
TeleEmail.PackReplyEmlAttachments(ContactRespID,ReplyEmailNameInZip,ChilkatE
mailOut,OutAttachmentFileNames,NumOfAttachments);
//TeleEmail.PackReplyEmlAttachments2(ContactRespID,ReplyEmailNameInZip,Chilk
atEmailOut,OutAttachmentFileNames,NumOfAttachments,ReplyAttShellListView);
Log('NumOfOutBound attachments: ' + IntToStr(NumOfAttachments));
end;