OV_FILE_SERVICE
Þ Note: Built-In Function Rules
Performs basic file and directory services.
Note: DO NOT ALTER this OV Built-In Function as it is used by LANSA programs. If you create a customized version of this Built-In Function, create a copy and amend the copy.
All Windows path names support environment variable substitution.
Note: The user of this Built-In Function is responsible for any impact it has on any application. No warranty of any kind is expressed or implied. Refer to full Disclaimer.
Function No: |
992 |
DLL Required: |
U_BIF992.DLL |
For use with
|
Arguments
|
Return Values
|
Examples
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) requests that you specify a directory name and then attempts to create it. The basic and extended return codes from the attempt to create the directory are displayed:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(65);
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
DEFINE FIELD(#OV_ERRNO) TYPE(*DEC) LENGTH(7) DECIMALS(0) EDIT_CODE(4);
BEGIN_LOOP;
MESSAGE MSGTXT('Specify name of directory to be created');
REQUEST FIELDS((#OV_DIRECT *NOID));
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(MAKE_DIR #OV_DIRECT) TO_GET(#OV_RETC #OV_ERRNO);
MESSAGE MSGTXT('Response from OV_FILE_SERVICE');
POP_UP FIELDS(#OV_RETC #OV_ERRNO);
END_LOOP;
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) creates a directory called C:\OV_DEMO and then creates directories A, B, C and D within it. It then destroys all the directories created. Note that this is done in reverse order because a directory must be empty to be removed (destroyed):
FUNCTION OPTIONS(*DIRECT);
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(MAKE_DIR 'C:\OV_DEMO');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(MAKE_DIR 'C:\OV_DEMO\A');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(MAKE_DIR 'C:\OV_DEMO\B');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(MAKE_DIR 'C:\OV_DEMO\C');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(MAKE_DIR 'C:\OV_DEMO\D');
MESSAGE MSGTXT('Directories all created .... use OK to delete them now');
POP_UP FIELDS((#DATE *L3 *P2)) AT_LOC(8 23) WITH_SIZE(55 10) EXIT_KEY(*NO) MENU_KEY(*NO) PROMPT_KEY(*NO);
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(REMOVE_DIR 'C:\OV_DEMO\A');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(REMOVE_DIR 'C:\OV_DEMO\B');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(REMOVE_DIR 'C:\OV_DEMO\C');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(REMOVE_DIR 'C:\OV_DEMO\D');
EXECUTE SUBROUTINE(DIRECT) WITH_PARMS(REMOVE_DIR 'C:\OV_DEMO');
MESSAGE MSGTXT('Directories all deleted .... use OK to end this function');
POP_UP FIELDS((#DATE *L3 *P2)) AT_LOC(8 23) WITH_SIZE(55 10) EXIT_KEY(*NO) MENU_KEY(*NO) PROMPT_KEY(*NO);
SUBROUTINE NAME(DIRECT) PARMS((#OV_SERV *RECEIVED) (#OV_DIRECT *RECEIVED));
DEFINE FIELD(#OV_SERV) TYPE(*CHAR) LENGTH(20);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(65);
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
DEFINE FIELD(#OV_ERRNO) TYPE(*DEC) LENGTH(7) DECIMALS(0) EDIT_CODE(4);
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(#OV_SERV #OV_DIRECT) TO_GET(#OV_RETC #OV_ERRNO);
IF COND('#OV_RETC *NE OK');
DISPLAY FIELDS(#OV_SERV (#OV_DIRECT *NOID) #OV_RETC #OV_ERRNO) EXIT_KEY(*NO) MENU_KEY(*NO) PROMPT_KEY(*NO);
ABORT MSGTXT('Directory Operation failed');
ENDIF;
ENDROUTINE;
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) asks you to nominate a directory name. If it does not already exist you are prompted as to whether you want to create it:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(70);
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
DEFINE FIELD(#OV_MBA) TYPE(*CHAR) LENGTH(1);
BEGIN_LOOP;
REQUEST FIELDS((#OV_DIRECT *NOID));
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(CHECK_DIR #OV_DIRECT) TO_GET(#OV_RETC);
IF COND('#OV_RETC = OK');
MESSAGE MSGTXT('This directory already exists');
ELSE;
USE BUILTIN(OV_MESSAGE_BOX) WITH_ARGS('Do you want to create this directory ?' 'Create ?' YN Q) TO_GET(#OV_MBA);
IF COND('#OV_MBA = Y');
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(MAKE_DIR #OV_DIRECT) TO_GET(#OV_RETC);
IF COND('#OV_RETC *NE OK');
MESSAGE MSGTXT('Attempt to create directory failed');
ENDIF;
ENDIF;
ENDIF;
END_LOOP;
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) asks you to nominate a file name and then indicates whether or not the file exists:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(70);
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
BEGIN_LOOP;
MESSAGE MSGTXT('Specify name of file whose existence is to be checked for');
REQUEST FIELDS((#OV_DIRECT *NOID));
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(CHECK_FILE #OV_DIRECT) TO_GET(#OV_RETC);
IF COND('#OV_RETC = OK');
MESSAGE MSGTXT('This file exists');
ELSE;
MESSAGE MSGTXT('This file does NOT exist');
ENDIF;
DISPLAY FIELDS((#OV_DIRECT *NOID));
END_LOOP;
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) asks you to nominate a file name and whether the file should be set to read only status or normal (read/write) status:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_FILE) TYPE(*CHAR) LENGTH(70);
DEFINE FIELD(#OV_READ) TYPE(*CHAR) LENGTH(1) LABEL('Read Only') INPUT_ATR(RB01) DEFAULT(1);
DEFINE FIELD(#OV_NORM) TYPE(*CHAR) LENGTH(1) LABEL('Normal') INPUT_ATR(RB01) DEFAULT(0);
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
**********;
BEGIN_LOOP;
MESSAGE MSGTXT('Specify name of file whose attribute is to be changed and select attribute');
REQUEST FIELDS((#OV_FILE *L3 *P2 *NOID) (#OV_READ *L5 *P3) (#OV_NORM *L7 *P3));
IF COND('#ov_read = ''1''');
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(SET_FILE #OV_FILE READ_ONLY) TO_GET(#OV_RETC);
ELSE;
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(SET_FILE #OV_FILE NORMAL) TO_GET(#OV_RETC);
ENDIF;
IF COND('#OV_RETC = OK');
MESSAGE MSGTXT('File attribute successfully changed');
ELSE;
MESSAGE MSGTXT('ERROR : File attribute was NOT changed');
ENDIF;
END_LOOP;
The following sample RDML function (which can be copied and pasted in the CS/400 free form function editor) asks you to nominate a from and to file name and then attempts to perform a copy operation:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_FROM) TYPE(*CHAR) LENGTH(60) DEFAULT('C:\CONFIG.SYS');
DEFINE FIELD(#OV_TO) TYPE(*CHAR) LENGTH(60) DEFAULT('C:\CONFIG.SAV');
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
**********;
BEGIN_LOOP;
MESSAGE MSGTXT('Specify the from and to file names');
REQUEST FIELDS(#OV_FROM #OV_TO);
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(COPY_FILE #OV_FROM #OV_TO) TO_GET(#OV_RETC);
IF COND('#OV_RETC = OK');
MESSAGE MSGTXT('File copied');
ELSE;
MESSAGE MSGTXT('ERROR : File was NOT copied correctly');
ENDIF;
END_LOOP;
The following sample RDML function asks you to nominate a directory name and then retrieves and displays its contents. The resulting contents display can be sorted into various orders. This example can be copied and pasted into the CS/400 free form editor but the long REQUEST command may have to be "unfolded" before the function will be accepted as valid RDML code:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(70);
DEFINE FIELD(#OV_FILTER) TYPE(*CHAR) LENGTH(3) LABEL('Optional Filter');
DEFINE FIELD(#OV_BYTES) TYPE(*DEC) LENGTH(9) DECIMALS(0) LABEL('Total of Sizes') EDIT_CODE(3);
DEFINE FIELD(#OV_OBJECT) TYPE(*DEC) LENGTH(7) DECIMALS(0) LABEL('Total Objects') EDIT_CODE(3);
DEF_COND NAME(*OBJECTS) COND('#ov_object *gt 0');
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
DEFINE FIELD(#OV_ERRN) TYPE(*DEC) LENGTH(15) DECIMALS(0);
DEFINE FIELD(#OV_NAME) TYPE(*CHAR) LENGTH(15);
DEFINE FIELD(#OV_PREFIX) TYPE(*CHAR) LENGTH(12);
DEFINE FIELD(#OV_SUFFIX) TYPE(*CHAR) LENGTH(3);
DEFINE FIELD(#OV_DATE) TYPE(*CHAR) LENGTH(8);
DEFINE FIELD(#OV_TIME) TYPE(*CHAR) LENGTH(6);
DEFINE FIELD(#OV_ISDIR) TYPE(*CHAR) LENGTH(1);
DEFINE FIELD(#OV_SIZE) TYPE(*DEC) LENGTH(9) DECIMALS(0) EDIT_CODE(3);
DEFINE FIELD(#OV_PB01) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB01) DEFAULT('''Order By Name''');
DEFINE FIELD(#OV_PB02) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB02) DEFAULT('''Order By Suffix''');
DEFINE FIELD(#OV_PB03) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB03) DEFAULT('''Order By Date/Time''');
DEFINE FIELD(#OV_PB04) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB04) DEFAULT('''Order By Size''');
DEF_LIST NAME(#WLIST) FIELDS(#OV_NAME #OV_PREFIX #OV_SUFFIX #OV_DATE #OV_TIME #OV_SIZE #OV_ISDIR) TYPE(*WORKING) ENTRYS(5000);
DEF_LIST NAME(#DLIST) FIELDS(#OV_NAME #OV_PREFIX #OV_SUFFIX #OV_DATE #OV_TIME #OV_SIZE #OV_ISDIR) COUNTER(#OV_OBJECT);
**********;
EXECUTE SUBROUTINE(WTOD);
BEGIN_LOOP;
REQUEST FIELDS((#OV_DIRECT *L3 *P2 *NOID) (#OV_FILTER *L4 *P2) (#OV_PB01 *L6 *P2 *NOID *OBJECTS *IOCOND) (#OV_PB02 *L8 *P2 *NOID *OBJECTS *IOCOND) (#OV_PB03 *L6 *P38 *NOID *OBJECTS *IOCOND)
(#OV_PB04 *L8 *P38 *NOID *OBJECTS *IOCOND) (#OV_BYTES *L4 *P22 *OUT) (#OV_OBJECT *L4 *P49 *OUT)) BROWSELIST(#DLIST);
CASE OF_FIELD(#IO$KEY);
WHEN VALUE_IS('= B1');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_NAME);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B2');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_SUFFIX #OV_PREFIX);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B3');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_DATE #OV_TIME);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B4');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_SIZE);
EXECUTE SUBROUTINE(WTOD);
OTHERWISE;
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(GET_DIR #OV_DIRECT #OV_FILTER) TO_GET(#OV_RETC #OV_ERRN #WLIST);
IF COND('#OV_RETC = OK');
EXECUTE SUBROUTINE(WTOD);
ELSE;
MESSAGE MSGTXT('ERROR: Unable to list specified directory ');
ENDIF;
ENDCASE;
END_LOOP;
**********;
SUBROUTINE NAME(WTOD);
CLR_LIST NAMED(#DLIST);
CHANGE FIELD(#OV_BYTES) TO(0);
SELECTLIST NAMED(#WLIST);
CHANGE FIELD(#OV_BYTES) TO('#ov_bytes + #ov_size');
ADD_ENTRY TO_LIST(#DLIST) WITH_MODE(*DISPLAY);
ENDSELECT;
ENDROUTINE;
The following sample RDML function asks you to nominate a directory name and then retrieves and displays its contents. The resulting contents display can be sorted into various orders. By double clicking on a displayed file name you can delete it. File deletion requests must be confirmed by clicking "Yes" in a message box. This example can be copied and pasted into the CS/400 free form editor but the long REQUEST command may have to be "unfolded" before the function will be accepted as valid RDML code:
FUNCTION OPTIONS(*DIRECT);
DEFINE FIELD(#OV_DIRECT) TYPE(*CHAR) LENGTH(70);
DEFINE FIELD(#OV_PIRECT) REFFLD(#OV_DIRECT);
DEFINE FIELD(#OV_FILTER) TYPE(*CHAR) LENGTH(3) LABEL('Optional Filter');
DEFINE FIELD(#OV_BYTES) TYPE(*DEC) LENGTH(9) DECIMALS(0) LABEL('Total of Sizes') EDIT_CODE(3);
DEFINE FIELD(#OV_OBJECT) TYPE(*DEC) LENGTH(7) DECIMALS(0) LABEL('Total Objects') EDIT_CODE(3);
DEFINE FIELD(#OV_SELECT) TYPE(*DEC) LENGTH(7) DECIMALS(0);
DEF_COND NAME(*OBJECTS) COND('#ov_object *gt 0');
DEFINE FIELD(#OV_RETC) TYPE(*CHAR) LENGTH(2);
DEFINE FIELD(#OV_ERRN) TYPE(*DEC) LENGTH(15) DECIMALS(0);
DEFINE FIELD(#OV_NAME) TYPE(*CHAR) LENGTH(15);
DEFINE FIELD(#OV_PREFIX) TYPE(*CHAR) LENGTH(12);
DEFINE FIELD(#OV_SUFFIX) TYPE(*CHAR) LENGTH(3);
DEFINE FIELD(#OV_DATE) TYPE(*CHAR) LENGTH(8);
DEFINE FIELD(#OV_TIME) TYPE(*CHAR) LENGTH(6);
DEFINE FIELD(#OV_ISDIR) TYPE(*CHAR) LENGTH(1);
DEFINE FIELD(#OV_SIZE) TYPE(*DEC) LENGTH(9) DECIMALS(0) EDIT_CODE(3);
DEFINE FIELD(#OV_PB01) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB01) DEFAULT('''Order By Name''');
DEFINE FIELD(#OV_PB02) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB02) DEFAULT('''Order By Suffix''');
DEFINE FIELD(#OV_PB03) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB03) DEFAULT('''Order By Date/Time''');
DEFINE FIELD(#OV_PB04) TYPE(*CHAR) LENGTH(30) INPUT_ATR(PB04) DEFAULT('''Order By Size''');
DEF_LIST NAME(#WLIST) FIELDS(#OV_NAME #OV_PREFIX #OV_SUFFIX #OV_DATE #OV_TIME #OV_SIZE #OV_ISDIR) TYPE(*WORKING) ENTRYS(5000);
DEF_LIST NAME(#DLIST) FIELDS(#OV_NAME #OV_PREFIX #OV_SUFFIX #OV_DATE #OV_TIME #OV_SIZE #OV_ISDIR) COUNTER(#OV_OBJECT) SEL_ENTRY(#OV_SELECT);
**********;
BEGIN_LOOP;
CHANGE FIELD(#OV_PIRECT) TO(#OV_DIRECT);
REQUEST FIELDS((#OV_DIRECT *L3 *P2 *NOID) (#OV_FILTER *L4 *P2) (#OV_PB01 *L6 *P2 *NOID *OBJECTS *IOCOND) (#OV_PB02 *L8 *P2 *NOID *OBJECTS *IOCOND) (#OV_PB03 *L6 *P38 *NOID *OBJECTS *IOCOND)
(#OV_PB04 *L8 *P38 *NOID *OBJECTS *IOCOND) (#OV_BYTES *L4 *P22 *OUT) (#OV_OBJECT *L4 *P49 *OUT)) BROWSELIST(#DLIST);
CASE OF_FIELD(#IO$KEY);
WHEN VALUE_IS('= B1');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_NAME);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B2');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_SUFFIX #OV_PREFIX);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B3');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_DATE #OV_TIME);
EXECUTE SUBROUTINE(WTOD);
WHEN VALUE_IS('= B4');
SORT_LIST NAMED(#WLIST) BY_FIELDS(#OV_SIZE);
EXECUTE SUBROUTINE(WTOD);
OTHERWISE;
IF COND('(#ov_pirect = #ov_direct) *and (#ov_select *gt 0) *and (#ov_object *gt 0)');
EXECUTE SUBROUTINE(DELETE_FIL);
ELSE;
EXECUTE SUBROUTINE(LOAD_DIR);
ENDIF;
ENDCASE;
END_LOOP;
**********;
SUBROUTINE NAME(LOAD_DIR);
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(GET_DIR #OV_DIRECT #OV_FILTER) TO_GET(#OV_RETC #OV_ERRN #WLIST);
IF COND('#OV_RETC = OK');
EXECUTE SUBROUTINE(WTOD);
ELSE;
MESSAGE MSGTXT('ERROR: Unable to list specified directory ');
ENDIF;
ENDROUTINE;
**********;
SUBROUTINE NAME(DELETE_FIL);
DEFINE FIELD(#OV_MBA) TYPE(*CHAR) LENGTH(1);
DEFINE FIELD(#OV_MSG) TYPE(*CHAR) LENGTH(100);
GET_ENTRY NUMBER(#OV_SELECT) FROM_LIST(#DLIST);
IF COND('#ov_isdir = Y');
MESSAGE MSGTXT('Selected object is a directory and cannot be deleted');
ELSE;
USE BUILTIN(BCONCAT) WITH_ARGS('Confirm that file' #OV_NAME 'is to deleted') TO_GET(#OV_MSG);
USE BUILTIN(OV_MESSAGE_BOX) WITH_ARGS(#OV_MSG 'Delete File' YN Q) TO_GET(#OV_MBA);
IF COND('#OV_MBA = Y');
USE BUILTIN(TCONCAT) WITH_ARGS(#OV_DIRECT '\' #OV_NAME) TO_GET(#OV_MSG);
USE BUILTIN(OV_FILE_SERVICE) WITH_ARGS(REMOVE_FILE #OV_MSG) TO_GET(#OV_RETC);
IF COND('#OV_RETC = OK');
EXECUTE SUBROUTINE(LOAD_DIR);
MESSAGE MSGTXT('File successfully deleted');
ELSE;
MESSAGE MSGTXT('ERROR : Attempt to delete file failed');
ENDIF;
ENDIF;
ENDIF;
ENDROUTINE;
**********;
SUBROUTINE NAME(WTOD);
CLR_LIST NAMED(#DLIST);
CHANGE FIELD(#OV_BYTES) TO(0);
SELECTLIST NAMED(#WLIST);
CHANGE FIELD(#OV_BYTES) TO('#ov_bytes + #ov_size');
ADD_ENTRY TO_LIST(#DLIST) WITH_MODE(*DISPLAY);
ENDSELECT;
ENDROUTINE;