Viewing contents of file '../idllib/contrib/tappin/graffer/gr_isadir.pro'
FUNCTION Gr_isadir, dir
;+
; GR_ISADIR
; Checks if its argument is a directory.
;
; Usage:
; ok = gr_isadir(dir)
;
; Return:
; 1 if it is, 0 if it isn't or isn't accessible by the user
;
; Argument:
; dir string input The putative directory to be tested
;
; History:
; Ripped straight out of PICKFILE and renamed: 16/1/97; SJT
;-
CASE !Version.os OF
'vms': BEGIN
CD, current = here ; get pwd
; VMS directories can be files,
; NAME.DIR, or paths
; DEVICE:[NAME.NAME].
; If the "[]" method is used, tack on
; a wildcard spec (*.*), otherwise
; the value of dir is a filename and
; it can remain the same.
if(strpos(dir, ']') gt -1)then dir = dir + "*.*"
context = 0L
resultant = STRING(BYTARR(256)+32B)
; See if either Name.dir file exists
; in the current directory or if a
; path specified see if there is any
; files in that dir. Use vms LIB$
; routines via Call External
result = CALL_EXTERNAL("LIBRTL", "LIB$FIND_FILE", dir, $
resultant, context, here, 0L, 0L, 0L, $
VALUE = [0, 0, 0, 0, 1, 1, 1])
toss = CALL_EXTERNAL("LIBRTL", "LIB$FIND_FILE_END", context)
RETURN, (result EQ 65537)
END
'Win32': BEGIN
RETURN, 1 ; Hook into common dialogs for windows
; when this really works.
END
Else: BEGIN
; Can't CD to a directory unless the
; user has execute permission. Use
; the unix command test to check
; this. Have to use sh5 on ultrix Test
; sets the shell status variable and
; echo prints it out. This is then
; captured by spawn and placed in
; result
if(!Version.os ne 'ultrix')then $
spawn, ['test -d "'+dir +'" -a -x "'+dir+'" ; echo $?'], $
result, /sh $
else $
spawn, ['/bin/sh5 -c "test -d '''+dir+''' -a -x '''+dir+''' ' + $
'";echo $?'], result, /sh
return, (not fix(result(0)) and 1) ;convert result to int and NOT it.
END
ENDCASE
END