;+ ; ; @file_comments ; check if a directory exists and make sure that it ends ; with the directory separator mark. ; ; @categories ; io ; ; @param DIRECTORYIN {in}{optional} ; a proposed directory. If neither dirname ; input parameter of IODIRECTORY keyword are defined, ; we ask the user to choose a directory. ; ; @keyword IODIRECTORY ; a proposed directory ; ; @keyword TITLE ; the title of the window ; ; @keyword _EXTRA ; Used to pass keywords to DIALOG_PICKFILE ; ; @returns ; the directory name ; ; @examples ; ; IDL> print, !dir ; /usr/local/rsi/idl_6.0 ; IDL> print, isadirectory(!dir) ; /usr/local/rsi/idl_6.0/ ; IDL> print, isadirectory(!dir+'notgood') ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; June 28, 2000 ; June 2005: Sebastien Masson: cleaning, use for file_* functions ; ; @version ; $Id$ ; ;- ; FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _EXTRA = ex ; compile_opt idl2, strictarrsubs ; CASE 1 OF (size(directoryin, /type))[0] EQ 7:directory = directoryin keyword_set(iodirectory):directory = iodirectory ELSE:directory = 'directory that is not existing' ENDCASE testfile = file_test(directory, /directory) ; if directory doesn't exist, we ask the user to provide a directory name IF total(testfile) NE n_elements(directory) THEN BEGIN IF NOT keyword_set(title) THEN title = 'choose a directory' FOR i = 0, n_elements(directory)-1 DO BEGIN IF testfile[i] EQ 0 THEN BEGIN directory[i] = dialog_pickfile(/directory, title = title $ , /must_exist, _extra = ex) if directory[i] EQ '' THEN RETURN, report('check/find directory canceled') ENDIF ENDFOR ENDIF ; directory = file_search(directory, /mark_directory, /test_directory, /fully_qualify_path) IF n_elements(directory) EQ 1 THEN RETURN, directory[0] $ ELSE RETURN, directory ; END