Writing file

Hi all!
I try to write file.

OUTPUT TO "/home/user1/dir1/111.txt".
  PUT UNFORMATTED "TEST1" SKIP.
  PUT UNFORMATTED "TEST2" SKIP.
OUTPUT CLOSE.

If directory "dir1" don't exists how can I catch write-error exception?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Possible solution

Hi,

You can use the FILE-INFO attributes to see if a directory exists or if you have rights for writing in it.

FILE-INFO:FILE-NAME = "/home/user1/dir1".

IF substring(FILE-INFO:FILE-TYPE,1,1) = "D"
THEN
MESSAGE 'Directory exist'
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
MESSAGE 'Directory doesn't exist'
VIEW-AS ALERT-BOX INFO BUTTONS OK.


Thanks for answer! But what

Thanks for answer!

But what should I do in next situation: "dir1" is mapping network resource and network link goes down at middle of writting?


Workaround

Hi,

I suggest you write the file on you local hard because put statement does not have an no-error option. After you are done with the file use OS-COPY to copy the file on the mapped directory.