File - Modification (示例)

(* 如何使用 CAA_FILE.library函数库示例 - 文件改变功能块 *)

PROGRAM FILE.CHANGE_PRG

VAR

                xFileChgInit:            BOOL:=FALSE;

                uiFileChgState:        UINT:=0;

                sFileOldName:         CAA.FILENAME:= 'TestFile.txt';

                sFileNewName:      CAA.FILENAME:= 'NewFile.txt';

                szCopiedFileSize:   CAA.SIZE := 0;

                filcp:                        FILE.Copy;

                filrn:                        FILE.Rename;

                fildl:                         FILE.Delete;

END_VAR

 

IF NOT xFileChgInit THEN

                fildl(xExecute:=FALSE);

                filrn(xExecute:=FALSE);

                filcp(xExecute:=FALSE);

                xFileChgInit:=TRUE;

                uiFileChgState:=0;

ELSE

                CASE uiFileChgState OF

                0:(*copy file *)

                               filcp.sFileNameSource:=sFileNewName;

                               filcp.sFileNameDest:='DestFile.txt';

                               filcp.udiTimeOut:=100000;                     (* 100ms Timeout    *)

                               filcp.xOverWrite:=TRUE;                        (* overwrite the existing file *)

                               filcp( xExecute:=TRUE);

                               IF filcp.xDone THEN

                                               szCopiedFileSize := filcp.szSize;

                                               uiFileChgState:=1;

                               END_IF

                               IF filcp.xError THEN

                                               (* error handling*)

                                               ;

                               END_IF

                1: (* rename file *)

                               filrn.sFileNameOld:='DestFile.txt';

                               filrn.sFileNameNew:=sFileNewName;

                                filrn( xExecute:=TRUE);

                               IF filrn.xDone THEN

                                               uiFileChgState:=2;

                               END_IF

                               IF filrn.xError THEN

                                               (* error handling*)

                                               ;

                               END_IF

                2:(* delete file *)

                               fildl.sFileName:=sFileNewName;

                               fildl( xExecute:=TRUE);

                               IF fildl.xDone THEN

                                               uiFileChgState:=3;

                               END_IF

                               IF fildl.xError THEN

                                               (* error handling*)

                                               ;

                               END_IF

                3:

                (* end of example*)

                               ;

                END_CASE

END_IF