;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME:isadirectory ; ; PURPOSE:check if a directory exists and make sure that it ends ; with the directory separator mark. ; ; CATEGORY: io ; ; CALLING SEQUENCE: directory=isadirectory([dirname]) ; ; INPUTS:optional:a proposed directory. If neither dirname ; input parameter of IODIRECTORY keyword are defined, ; the ask the user to choose a directory. ; ; KEYWORD PARAMETERS: ; ; IODIRECTORY:a proposed directory ; ; TITLE = the title of the window ; ; all dialog_pickfile keywords (like filter) ; ; OUTPUTS: the directory name ; ; COMMON BLOCKS:none ; ; SIDE EFFECTS: ; ; RESTRICTIONS: ; ; EXAMPLE: ; ; IDL> print, !dir ; /usr/local/rsi/idl_6.0 ; IDL> print, isadirectory(!dir) ; /usr/local/rsi/idl_6.0/ ; IDL> print, isadirectory(!dir+'notgood') ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; June 28, 2000 ; June 2005: Sebastien Masson: cleaning, use for file_* functions ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION isadirectory, directoryin, TITLE = title, IODIRECTORY = iodirectory, _extra = ex ; 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) IF n_elements(directory) EQ 1 THEN RETURN, directory[0] $ ELSE RETURN, directory ; END