cA710 ;I/O and OS operations ;%A710; [ 07/30/01 10:10 AM ] G YZ ; OR(R) ; Open file R for read ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext N ER,T S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $$TST(R) Q 3 ; file does not exist I $ZV["MSM" O 53:(R:"R") U 53:(R) S ER=$ZA I ER<0 S ER=2 C 53 I $ZV'["MSM" O R:"R":3 S T=$T S:'T ER=2 I T U R Q ER ; ORF(R,L) ; Open file R for read with fixed length L ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; L is the length of the records you want to read N ER,T S $ZT="ERR",R=$G(R),L=+$G(L),ER=0 I '$L(R) Q 1 I $$TST(R) Q 3 ; file does not exist I $ZV["MSM" O 53:(R:"R") U 53:(R) S ER=$ZA I ER<0 S ER=2 C 53 I $ZV'["MSM" O R:("RF":L):3 S T=$T S:'T ER=2 I T U R Q ER ; OW(R) ; Open file R for write ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext N ER,T S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $ZV["MSM" O 53:(R:"W") U 53:(R) S ER=$ZA I ER<0 S ER=2 C 53 I $ZV'["MSM" O R:"WNS":3 S T=$T S:'T ER=2 I T U R Q ER ; OA(R) ; Open file R for append ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext N ER,T S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $ZV["MSM" O 53:(R:"A") U 53:(R) S ER=$ZA I ER<0 S ER=2 C 53 I $ZV'["MSM" O R:"WAS":3 S T=$T S:'T ER=2 I T U R Q ER ; CF(R) ; Close file R ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $ZV["MSM" C 53:(R) I $ZV'["MSM" C R I '$T S ER=2 Q ER ; RF(R,K) ; Read from file R into K ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K has to be passed by reference, i.e. S ER=$$RF(file,.A) puts ;; the error in ER and returns the string read into A ;; If ER=99 = End of File the value returned will be the empty string N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $$TST(R) Q 3 ; file does not exist I $ZV["MSM" U 53:(R) R K S ER=$ZC I ER=-1 S ER=99 ; 99 = EOF I $ZV'["MSM" U R R K Q ER ; RFF(R,K,L) ; Read from file R into K with fixed length L ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K has to be passed by reference, i.e. S ER=$$RF(file,.A) puts ;; the error in ER and returns the string read into A ;; L is the length of the records you want to read ;; If ER=99 = End of File the value returned can contain data if the ;; the size of the file is not a multiple of the recordlength you ;; read. You should check the variable for a non-empty string. N ER S $ZT="ERR",R=$G(R),L=+$G(L),ER=0 I '$L(R) Q 1 I $$TST(R) Q 3 ; file does not exist I $ZV["MSM" U 53:(R:::::"") R K#L S ER=$ZC I ER=-1 S ER=99 ; 99 = EOF I $ZV'["MSM" U R R K Q ER ; WF(R,K) ; Write to file R string K ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K contains the data you want to write INCLUDING record separators ;; i.e. S ER=$$WF(file,data_$c(13,10)) is equal to 'W data,!' N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $$TST(R) Q 3 ; file does not exist I $ZV["MSM" U 53:(R) W K S ER=$ZC I $ZV'["MSM" U R W K Q ER ; FS(R,K) ; Get size of File R into K ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K has to be passed by reference, i.e. S ER=$$FS(file,.A) puts ;; the error in ER and returns the file size into A N ER S $ZT="ERR",R=$G(R) I $$TST(R) Q 1 ; file does not exist I $ZV["MSM" S ER=$ZOS(12,R,16+4+1) D . I ER<0 S ER=2 Q . I $L(ER,"^")<1 S ER=3 Q . S K=$P(ER,"^",2,99),ER=0,K=$ZASCII(K,27)+($ZASCII(K,28)*256)+($ZASCII(K,29)*256*256)+($ZASCII(K,30)*256*256*256) I $ZV'["MSM" D . S ER=0,K=$ZU(140,1,R) I K<0 S ER=2 Q ER ; FCD(R,K) ; Get file creation date of File R into K ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K has to be passed by reference, i.e. S ER=$$FS(file,.A) puts ;; the error in ER and returns the date into A N ER S $ZT="ERR",R=$G(R) I $$TST(R) Q 1 ; file does not exist I $ZV["MSM" S ER=$ZOS(12,R,16+4+1) D . N %A,%B,%C,%D,%E,%DS,%DN,%TS,%TN . I ER<0 S ER=2 Q . I $L(ER,"^")<1 S ER=3 Q . S K=$P(ER,"^",2,99),ER=0,%A=$ZASCII(K,25),%B=$ZASCII(K,26),%C=256*%B+%A,%D=%C#32,%C=%C\32,%E=%C#16,%C=%C\16,%C=%C+1980 . S %DS=%E_"-"_$E("00",1,2-$L(%D))_%D_"-"_%C D ^cDI . S %A=$ZASCII(K,23),%B=$ZASCII(K,24),%C=%B*256+%A,%D=%C#32*2,%C=%C\32,%E=%C#64,%C=%C\64,%A=%C\12,%B=%C#12 S:%B=0 %B=12 . S %TS=%B_":"_$E("00",1,2-$L(%E))_%E_$S(%A:"P",1:"A") D ^cTI . S K=%DN_","_%TN I $ZV'["MSM" D . S K=$ZU(140,3,R),ER=0 I K<0 S ER=2 Q ER ; FMD(R,K) ; Get file modificaton date of File R into K ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; K has to be passed by reference, i.e. S ER=$$FS(file,.A) puts ;; the error in ER and returns the date into A N ER S $ZT="ERR",R=$G(R) I $$TST(R) Q 1 ; file does not exist I $ZV["MSM" S ER=$ZOS(12,R,16+4+1) D . N %A,%B,%C,%D,%E,%DS,%DN,%TS,%TN . I ER<0 S ER=2 Q . I $L(ER,"^")<1 S ER=3 Q . S K=$P(ER,"^",2,99),ER=0,%A=$ZASCII(K,25),%B=$ZASCII(K,26),%C=256*%B+%A,%D=%C#32,%C=%C\32,%E=%C#16,%C=%C\16,%C=%C+1980 . S %DS=%E_"-"_$E("00",1,2-$L(%D))_%D_"-"_%C D ^cDI . S %A=$ZASCII(K,23),%B=$ZASCII(K,24),%C=%B*256+%A,%D=%C#32*2,%C=%C\32,%E=%C#64,%C=%C\64,%A=%C\12,%B=%C#12 S:%B=0 %B=12 . S %TS=%B_":"_$E("00",1,2-$L(%E))_%E_$S(%A:"P",1:"A") D ^cTI . S K=%DN_","_%TN I $ZV'["MSM" D . S K=$ZU(140,2,R),ER=0 I K<0 S ER=2 Q ER ; TST(R) ; Check if file or dir R exists ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; if R ends with a '\' we asume it's a directory. ;; BEWARE: you cannot test for the existance of a share !! ;; i.e. if \\system\share exists, you must either test ;; - a file: S ER=$$TST("\\system\share\file.ext") ;; or ;; - a directory: S ER=$$TST("\\system\share\dir\") N ER S $ZT="ERR",R=$TR($G(R),"/","\"),ER=2 I '$L(R) Q 1 I $ZV["MSM" S ER=$ZOS(12,R,"") D . I $E(R,$L(R))="\" S ER=$S(ER="":0,1:2) Q . S ER=$S($L(ER,"^")>1:0,1:2) I $ZV'["MSM" D . I $E(R,$L(R))="\" S R=$E(R,1,$L(R)-1) . S ER=$ZU(140,4,R) I ER'=0 S ER=2 Q ER ; DEL(R) ; Delete file R ;; R can be x:\dir\file.ext or \\system\share\dir\file.ext ;; if the file does not exist, you get 'succesfully' deleted N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $$TST(R) Q 0 ; file does not exist I $ZV["MSM" S ER=$ZOS(2,R) I +ER'=0 S ER=2 I $ZV'["MSM" S ER=$ZU(140,5,R) I ER'=0 S ER=2 Q ER ; REN(R,S) ; Rename file R to S ;; R & S can be x:\dir\file.ext or \\system\share\dir\file.ext N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 S S=$G(S),ER=0 I '$L(S) S ER=2 Q 3 I $$TST(R) Q 4 ; file does not exist I $ZV["MSM" S ER=$ZOS(3,R,S) I +ER'=0 S ER=2 I $ZV'["MSM" S ER=$ZU(140,6,R,S) I ER'=0 S ER=2 Q ER ; CRED(R) ; Create directory R ;; R can be x:\dir or \\system\share\dir ;; if the directory already exists, you get 'succesfully' created N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I '$$TST(R) Q 0 ; directory does already exist I $ZV["MSM" S ER=$ZOS(6,R) I +ER'=0 S ER=2 I $ZV'["MSM" S ER=$ZU(140,9,R) I ER'=0 S ER=2 Q ER ; DELD(R) ; Delete directory R ;; R can be x:\dir or \\system\share\dir ;; if the directory does not exist, you get 'succesfully' deleted N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $$TST(R) Q 0 ; directory does not exist I $ZV["MSM" S ER=$ZOS(7,R) I +ER'=0 S ER=2 I $ZV'["MSM" S ER=$ZU(140,10,R) I ER'=0 S ER=2 Q ER ; JW(R) ; Start program at OS level and wait until the program finishes ;; Example: S ER=$$JW("C:\Program Files\pcAnywhere\Awhost.exe") N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $ZV["MSM" S ER=$$JOBWAIT^cHOSTCMD(R) I $ZV'["MSM" S ER=$ZF(-1,R) Q ER ; JN(R) ; Start program at OS level and DON'T wait for the program to end ;; Example: S ER=$$JN("C:\Program Files\pcAnywhere\Awhost.exe") N ER S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $ZV["MSM" S ER=$$JOB^cHOSTCMD(R) I $ZV'["MSM" S ER=$ZF(-2,R) Q ER ; YZ Q ; ERR N ER S ER=999 I $ZV["MSM" D . I $L(R) C 53:(R) I $ZV'["MSM" D . I $L(R) C R . I $ZE["" S ER=99 Q . I $ZE["" S ER="11,"_$ZE Q . I $ZE["" S ER=12_","_$ZE Q . I $ZE["" S ER=13_","_$ZE Q . I $ZE["" S ER=14_","_$ZE Q ER ; ZZ ; 06.08.01 - 17 u 28 * V7.87