;+ ; NAME: checkdir ; ; PURPOSE: Check whether a given directory exists ; ; NOTES: ; Given a string supposedly naming a directory, checks whether it ; (a) corresponds to a valid directory ; (b) has a trailing slash present ; If (a) fails, the routine stops and gives an error. ; if (b) fails, the routine silently adds a slash. ; ; If called with /expand, it will expand any ~usernames in the ; given string to the full directory path needed by IDL. ; ; If called with /make, it will create the directory if needed. ; ; USAGE: ; checkdir, dir ; ; INPUTS: dir String containing a directory ; KEYWORDS: ; expand expand ~'s in the path. ; fallback if dir doesn't exist, try using this one instead ; ; HISTORY: ; Aug 21, 2001 MDP ; 2003 June 25 Added fallback option. MDP ; 2005 Sept 21 Added /make MDP ;- PRO checkdir,dir,expand=expand,fallback=fallback,make=make if keyword_set(expand) then dir=expand_path(dir) if not(keyword_set(dir) )then $ message,"No directory variable passed, or dir undefined!" if ( strmid(dir, strlen(dir)-1,1) ne "/") then dir=dir+"/" if dir_exist(dir) then return if keyword_set(fallback) then begin fbdir = fallback if keyword_set(expand) then fbdir=expand_path(fallback) if ( strmid(fbdir, strlen(fbdir)-1,1) ne "/") then fbdir=fbdir+"/" if dir_exist(fbdir) then begin message,/info,"Directory "+dir+" does not exist. Using "+fbdir+" instead." dir = fbdir return endif endif if keyword_set(make) then begin print,"Directory "+dir+" does not exist. Creating it!" file_mkdir,dir return endif message,"Directory "+dir+" does not exist!" end