I've just discovered the ftype verb in the files.ijs system library.
Looks useful replacement for my home-grown direxist.
However I think it has a logic bug.
NB. =========================================================
NB.*ftype v file type
NB.
NB. return 0 = not exist
NB. 1 = file
NB. 2 = directory (optionally ending in path separator)
ftype=: 3 : 0
d=. 1!:0 fboxname y
if. #d do.
>: 'd' = 4 { > 4 { ,d
elseif. PATHSEP_j_ = {: ucp y do.
d=. 1!:0 fboxname }: ucp y
2 * 'd' = 4 { > 4 { ,d
elseif. do.
0
end.
)
As currently defined ftype will not handle the case where a non-existing
directory path ending with a path separator is given.
ftype jpath '~system'
2
ftype (jpath '~system'),PATHSEP_j_
2
ftype (jpath '~system\notexist'),PATHSEP_j_
|index error: ftype
| 2*'d'=4{>4 {,d
A not particularly elegant solution is as follows:
ftype=: 3 : 0
d=. 1!:0 fboxname y
if. #d do.
>: 'd' = 4 { > 4 { ,d
elseif. PATHSEP_j_ = {: ucp y do.
d=. 1!:0 fboxname }: ucp y
if. #d do.
2 * 'd' = 4 { > 4 { ,d
else.
0
end.
elseif. do.
0
end.
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm