There are several utils in files require'files dir' fexist'c:\temp\dummi' 0 fexist'c:\temp\test.txt' 1
2010/3/26, Sprague, Webb (OFM) <[email protected]>: > Hi everyone, > > Probably my last question for the week :) -- can I get help in writing a > function, perhaps with some explanation for the approach? > > I would like a function that checks a file's existence; if the file is > does not exist, I want to write out a message to the console and (in my > non-J/APL lingo) throw an error to stop all execution (i.e. "barf"). If > the file does exist, I would like to read in the contents and "return" > all the data. > > My rationale is that the script I am maintaining has a bunch of fread > calls which throw domain errors if the file does exist, but I have no > clue what file is trying to be read since "domain error" refers to the > fact that the script is trying to concatenate a -1 return of fread with > a path. > > Also, the "big" script has several scripts in a single file, including > the one that reads in all the data, but the J debugger gives the line > number *within a function* so I don't know which line that is within the > script (though I could maybe do a little bit of math ....) > > Here is my feeble attempt at my desired function: > > readfile =: 3 : 0 > if. fexist y do. > out .= fread y > else. > ('readfile: ', y, ' does not exist') > this_is_supposed_to_bomb .= > end. > out > ) > > But here is the result: > > 1!:43 '' NB. thanks for the pointer to vocab -> foreigns > c:\j504 > readfile 'version_bin.txt' NB. I know this file exists > readfile 'version_bin.txt' > |control error: readfile > | readfile'version_bin.txt' > |[-0] > > I hope I am not trying everybody's patience too extremely. I do swear I > try to figure these things out from the documentation, but as I said > earlier I am trying to get up to speed more quickly than allows me to > really deal with J/APL in depth. I can only hope that your collective > answers to my cookbook-ish questions will provide a resource for others > later. > > Thanks! > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Björn Helgason, Verkfræðingur Fornustekkum II 781 Hornafirði, t-póst: [email protected] gsm: +3546985532 sími: +3544781286 http://groups.google.com/group/J-Programming Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans góður kennari getur stigið á tær án þess að glansinn fari af skónum /|_ .-----------------------------------. ,' .\ / | Með léttri lund verður | ,--' _,' | Dagurinn í dag | / / | Enn betri en gærdagurinn | ( -. | `-----------------------------------' | ) | (\_ _/) (`-. '--.) (='.'=) ♖♘♗♕♔♙ `. )----' (")_(") ☃☠ ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
