cA710 ;I/O and OS operations ;%A710; [ 07/30/01 10:10 AM ] G YZ ;errorcode cache ; -2 = file/directory not found. ; -3 = pathname not found. ; -5 = access denied (usually named item is a directory, not a file) ; -12 = invalid access (usually user does not have read permission) ;-183 = directory already exists ;Find errorcodes: Net helpmsg x ;Examples: ;net helpmsg 53 ; the network path was not found ;net helpmsg 123 ; The filename, directory name, or volume label syntax is incorrect. ; 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 ORZ 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 ORFZ 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 OWZ 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 OAZ 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 CFZ 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,K="" 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 RFZ 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,K="" 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 RFFZ 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 WFZ 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" S ER=0,K=$ZU(140,1,R) I K<0 S ER=2 FSZ 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" S K=$ZU(140,3,R),ER=0 I K<0 S ER=2 FCDZ 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" S K=$ZU(140,2,R),ER=0 I K<0 S ER=2 FMDZ Q ER ; TST(R) ; Check if file or dir R exists ;; R can be x:\dir\file.ext, \\system\share\dir\file.ext or x:\dir or \\system\dir or \\system\share\ 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 . S ER=$ZU(140,4,R) . I ER S R=$S($E(R,$L(R))="\":$E(R,1,$L(R)-1),1:R_"\") S ER=$ZU(140,4,R) TSTZ 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) S:ER=-2 ER=0 DELZ 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) RENZ 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,I S $ZT="ERR",R=$G(R),ER=0 I '$L(R) Q 1 I $E(R,$L(R))="\" S R=$E(R,1,$L(R)-1) F I=$E(R,1,2)="\\"*3+2:1:$L(R,"\") S ER=$$CREA($P(R,"\",1,I)) Q:ER Q ER CREA(R) 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) S:ER=-183 ER=0 CREDZ 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) S:ER=-2 ER=0 DELDZ 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) JWZ 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) JNZ Q ER ; UNIB(R) ;S ER=$$UNIB^cA710(file) to create a file in Unicode - Big Endian (Unix) N ER S ER=$$WF(R,$C(255,254)) I ER Q ER UNIBZ S ER=$$CP(R,"UNIB") Q ER ; UNIL(R) ;S ER=$$UNIL^cA710(file) to create a file in Unicode - Little Endian (Windows) N ER S ER=$$WF(R,$C(255,254)) I ER Q ER UNILZ S ER=$$CP(R,"UNIL") Q ER ; UTF8(R) ;S ER=$$UTF8^cA710(file) to create file in UTF-8 encoding N ER S ER=$$WF^cA710(R,$C(239,187,191)) I ER Q ER UTF8Z S ER=$$CP(R,"UTF8") Q ER ; CP(R,C) ;Set codepage C for file R N ER S R=$G(R,0),C=$G(C,"RAW"),C=$S(C="UNIB":"UnicodeBig",C="UNIL":"UnicodeLittle",1:C) U R S ER=$$SetIO^%NLS(C) I $$GetIO^%NLS()=C Q 0 CPZ Q 1 ; CPY(S,T) ; Copy source file S to destination file T N ER,i,I F i="S","T" S @(i)=$G(@(i)) ; I '$L(S) S ER=15_D_"source is null string" G CPYZ I '$L(T) S ER=16_D_"destination is null string" G CPYZ ; S ER=$$CRED($P(T,"\",1,$L(T,"\")-1)) I ER G CPYZ S ER=$$JW("copy """_S_""" """_T_""" /v /y") ;copy file ; CPYZ Q ER ; 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 ERRZ Q ER ; BEST(STR) ; Omvormen string naar juist formaat voor bestandslocatie S $ZT="TRAP^cAN000" N J S STR=$TR(STR,"/","\"),J=$E(STR),STR=$E(STR,2,$L(STR)) F Q:STR'["\\" S STR=$P(STR,"\\")_"\"_$P(STR,"\\",2,$L(STR)) BESTZ Q J_STR ; YZ Q ; ZZ ; 08.02.08 - 15 u 00 * V9.00