;+ ; NAME: ; CheckDir ; PURPOSE: ; Check whether a directory exists ; CATEGORY: ; Environment ; CALLING SEQUENCE: FUNCTION CheckDir, Name, LongName, stay=stay, silent=silent ; INPUTS: ; Name scalar string, the directory name ; Name='' always returns status=1B with ; LongName set to the current directory. ; OPTIONAL INPUT PARAMETERS: ; /stay if set then a 'cd' to the directory is made (if it exists) ; OUTPUTS: ; Status 0 : directory doesn't exist ; 1 : directory exists ; OPTIONAL OUTPUT PARAMETERS: ; LongName scalar string ; Status=0 : null string ; Status=1 : fully qualified directory name ; INCLUDE: @compile_opt.pro ; On error, return to caller ; RESTRICTIONS: ; > No attempt is made to pre-process the input directory name ; (such as translation of logicals/env. variables, etc.) ; CALLS: ; InitVar, hide_env, who_am_i ; PROCEDURE: ; > CD is used to decide whether a directory exists, and is ; used to retrieve the full directory name. ; > filepath is called to make sure a trailing (back)slash is appended on ; Unix and Windows systems. ; MODIFICATION HISTORY: ; DEC-1997, Paul Hick ; SEP-2002, Paul Hick (UCSD/CASS) ; Return zero if input spec contains wildcard. ; FEB-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added name of calling routine to informational message. ;- ; On Linux if Name contains a trailing * the cd may actually succeed ; (the wildcard is apparently ignored). IF strpos(Name,'*') NE -1 THEN RETURN, 0 InitVar, stay , /key InitVar, silent , 0 cd, current=old ; First pick up the current directory. catch, Error ; Returns, 0 if next CD fails IF Error EQ 0 THEN BEGIN cd, Name ; Test for existing by changing directory CASE stay OF 0: cd, old, current=LongName; Restore current dir; pick up full path 1: cd, current=LongName ENDCASE LongName = filepath(root=LongName,'') ENDIF catch, /cancel IF Error NE 0 THEN BEGIN LongName = '' IF silent LE 0 THEN message, /info, who_am_i(/caller)+': '+hide_env(Name)+' does not exist' ENDIF RETURN, Error EQ 0 & end