add2path.pro 805 Bytes
FUNCTION add2path,directory=directory

  IF keyword_set(directory) THEN BEGIN
      dir=directory
  ENDIF ELSE BEGIN
      dir=dialog_pickfile(/directory)
  ENDELSE

  path_elem=strsplit(!path,!psep,/extract)
  Npath_elem=(size(path_elem))(1)

  tobeadded=expand_path('+'+dir)
  tobeadded=strsplit(tobeadded,!psep,/extract)
  N2beadded=(size(tobeadded))(1)

  new_path=!path
  Nadded=0
  FOR i=0,N2beadded-1 DO BEGIN
      ind=where(path_elem EQ tobeadded(i),count)
                                ;  stop
      IF count EQ 0 THEN BEGIN
          new_path=new_path+!psep+tobeadded(i)
          message,'Adding to the path :'+tobeadded(i),/info
          Nadded=Nadded+1
      ENDIF
  ENDFOR


  IF Nadded EQ 0 THEN BEGIN
      message,'Nothing was added to the path',/info
  ENDIF

  RETURN,new_path

END