Move a XML File - EDI

Hi Folks…

trying to move a EDI.xml file from 1 folder to another via Codeunit…

from the code below it’s falling over on the MoveFTPFile function. Althought the files exist. it report that the files dones’t?

within the Nikesetup table both the export path exist.

OnRun()
NikeSetup.GET;
NikeSetup.TESTFIELD(Enabled);

NikeSetup.TESTFIELD(“Order Export Path”);
NikeSetup.TESTFIELD(“Processed Order Export Path”);
SendOrders();

SendOrders()
//Find Files

lRecNikePurchaseOrder.SETCURRENTKEY(“XML Status”);
lRecNikePurchaseOrder.SETFILTER(“XML Status”, ‘%1’, lRecNikePurchaseOrder.“XML Status”::Created);
IF lRecNikePurchaseOrder.ISEMPTY() THEN
EXIT;

//Does Order Exist?
CLEAR(CommitReq);
IF lRecNikePurchaseOrder.FINDSET() THEN BEGIN
REPEAT
IF CheckOrderExists(lRecNikePurchaseOrder) THEN
CommitReq := TRUE;
UNTIL lRecNikePurchaseOrder.NEXT() = 0;
IF CommitReq THEN
COMMIT;
END;

//Does File Exist?
CLEAR(CommitReq);
lRecNikePurchaseOrder.RESET;
lRecNikePurchaseOrder.SETCURRENTKEY(“XML Status”);
lRecNikePurchaseOrder.SETFILTER(“XML Status”, ‘%1’, lRecNikePurchaseOrder.“XML Status”::Created);
IF lRecNikePurchaseOrder.FINDSET(FALSE) THEN BEGIN
REPEAT
lRecPurchaseHeader.GET(lRecPurchaseHeader.“Document Type”::Order,lRecNikePurchaseOrder.“No.”);
FileName := lRecPurchaseHeader.“XML Filename” ;
IF EXISTS(NikeSetup.“Order Export Path” + FileName) THEN BEGIN
TEMPPurchaseHeader.INIT;
TEMPPurchaseHeader.“Document Type” := TEMPPurchaseHeader.“Document Type”::Order;
TEMPPurchaseHeader.“No.” := lRecNikePurchaseOrder.“No.”;
TEMPPurchaseHeader.“XML Filename” := lRecPurchaseHeader.“XML Filename”;
IF TEMPPurchaseHeader.INSERT THEN;
END ELSE BEGIN
lRecNikeLog.INIT;
lRecNikeLog.“Entry No.” := 0;
lRecNikeLog.Type := lRecNikeLog.Type::Export ;
lRecNikeLog.“Document No.” := lRecNikePurchaseOrder.“No.” ;
lRecNikeLog.Description := STRSUBSTNO(‘The XML File %1 does not exist’, FileName) ;
lRecNikeLog.Error := TRUE;
lRecNikeLog.INSERT(TRUE);
CommitReq := TRUE;

END;
UNTIL lRecNikePurchaseOrder.NEXT() = 0;
IF CommitReq THEN
COMMIT;
END;

//Process Found Records
IF TEMPPurchaseHeader.FINDSET THEN BEGIN
REPEAT
lRecNikeLog.INIT;
lRecNikeLog.“Entry No.” := 0;
lRecNikeLog.Type := lRecNikeLog.Type::Export ;
lRecNikeLog.“Document No.” := TEMPPurchaseHeader.“No.” ;
lRecNikeLog.Description := ‘The XML File could not be sent’ ;
lRecNikeLog.Error := TRUE;
lRecNikeLog.“XML File Name” := TEMPPurchaseHeader.“XML Filename”;
lRecNikeLog.INSERT(TRUE);

COMMIT;

ErrorMessage := ProcessFTPOrder(TEMPPurchaseHeader.“No.”);

IF ErrorMessage = ‘’ THEN BEGIN
lRecNikeLog.Description := ‘XML File sent successfully’;
lRecNikeLog.Error := FALSE;
IF (NOT MoveFTPFile(lRecNikeLog.“XML File Name”,
NikeSetup.“Order Export Path”,NikeSetup.“Processed Order Export Path”)) THEN BEGIN
ERROR(‘Unable to Move File %1 to Processed Folder.’, lRecNikeLog.“XML File Name”);

END

MoveFTPFile(FileName : Text[30];FromPath : Text[250];ToPath : Text[250]) : Boolean
OrigFile.RESET;
OrigFile.SETFILTER(Path,’%1’, FromPath);
OrigFile.SETFILTER(“Is a file”,’%1’,TRUE);
OrigFile.SETFILTER(Name, FileName);
IF OrigFile.FINDFIRST THEN BEGIN
//Does Processed File Already Exist
ProcFile.RESET;
ProcFile.SETFILTER(Path,’%1’, ToPath);
ProcFile.SETFILTER(“Is a file”,’%1’,TRUE);
ProcFile.SETFILTER(Name, FileName);
IF ProcFile.FINDFIRST THEN BEGIN
IF NOT ERASE(ToPath + FileName) THEN
EXIT(FALSE);
END ELSE
ProcFile.Path := ToPath;

IF RENAME(OrigFile.Path + OrigFile.Name, ProcFile.Path + OrigFile.Name) THEN
EXIT(TRUE);
END;
EXIT(FALSE);

Nav 2009 R2 ClassicClient

any advise would be helpful

Regards

Paddy

You can use :

COPY(OldPath+ SFile2.Name,NewPath + SFile2.Name);

ERASE(OldPath+ SFile2.Name);

Thanks for Anil…

I changed the code & OrigFile to a temp within the MoveFTPFile funct. and it works fine again now.

CLEAR(NikePOFileName);

NikePOFileName := NikeSetup.“Order Export Path” + FileName;

IF EXISTS(NikePOFileName) THEN
BEGIN
CLEAR(OrigFile);
OrigFile.Path := OrigFile.Path + FromPath;
OrigFile.“Is a file” := TRUE;
OrigFile.Name := FileName;
OrigFile.INSERT;
END;

ProcFile.RESET;
ProcFile.SETFILTER(Path,’%1’, ToPath);
ProcFile.SETFILTER(“Is a file”,’%1’,TRUE);
ProcFile.SETFILTER(Name, FileName);
IF ProcFile.FINDFIRST THEN BEGIN
IF NOT ERASE(ToPath + FileName) THEN
EXIT(FALSE);
END ELSE
ProcFile.Path := ToPath;

IF RENAME(OrigFile.Path + OrigFile.Name, ProcFile.Path + OrigFile.Name) THEN
EXIT(TRUE);
END;

EXIT(FALSE); IF NOT OrigFile.ISEMPTY THEN BEGIN

Boss you verified your own reply