[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Path handling in different OSs??



no, but here's a start if you don't even know how to begin. funny,
i just wrote this last night. it doesn't do what you want, it adds
the passed or current dir to IDL's !path variable.

good luck,
todd b

;////////////////////////////////
function tbAddToPath, pathString, APPEND=append, TREE=tree,
WIDGROUPLEADER=widGroupLeader
;+
; NAME:
;  tbAddToPath
;
; PURPOSE:
;  This function creates a new path string by adding pathString to the IDL
!path var.
;
; CATEGORY:
;  Utility.
;
; CALLING SEQUENCE:
;  retCode = tbAddToPath(pathString, APPEND=0, TREE=1,
WIDGROUPLEADER=widGroupLeader)
;
; INPUTS:
;  pathString: Sting containg the directory to add to the current !path
;  IDL path variable. If not supplied, adds the current working directory.
;
; KEYWORDS:
;  APPEND: Setting this keyword appends new path info to end of !path.
;   By default, adds it to the beginning.
;  TREE: Set this keyword to include sub directories of the dir to !path.
;   Unfortunately, only sub dirs with .pro or .sav files in them will be
included.
;   See IDL docs on paths.
;  WIDGROUPLEADER: Set this keyword to the group leader widget id.
;
; OUTPUTS:
;  Returns a string with the newly created path, or NULL ("") if theres a
problem.
;
; SIDE EFFECTS:
;  Displays an error dialog in catch block.
;
; RESTRICTIONS:
;  The "Warning" Dialog_Message dialog is used.
;
; USES:
;  Error_Message() from DFanning library
;
; EXAMPLE:
;  retCode = tbAddToPath(pathString, /append, WIDGROUPLEADER=widGrpLdr)
;
; MODIFICATION HISTORY:
;  Written by: Todd Bowers, 02 Feb 2000.
;  Modified:
;-

 ;//Error Handling code///////////
 catch, errorCode
 if (errorCode NE 0) then begin
  ;//Cancel this error handling block
  catch, /cancel
  ;//IDL's error message
  systemAnswer = Error_Message(/Traceback)
  ;//Application's error message
  message, "|ERROR| In function tbAddToPath(). Returning NULL
  return, ""
 endif
 ;////////////////////////////////

 ;////////////////////////////////
 ;//Check to see if var's/keywords passed. If not, give default values.
 if n_elements(pathString) EQ 0 then begin
  ;//Use current working directory
  cd, CURRENT=pathString
 endif
 ;////////////////////////////////

 ;////////////////////////////////
 ;//What's proper path delimeter for this OS?
 case (strlowcase(!VERSION.OS_FAMILY)) of
  "unix"  : pathDelim = ":"
  "windows" : pathDelim = ";"
  "win32"  : pathDelim = ";" ;IDL4.0
  else   : pathDelim = "," ;macOS and VMS
 endcase

 ;//Do you want to add this dir's subdir's too?
 if n_elements(tree) EQ 0 then $
  addPath = expand_path(pathString, COUNT=dirCount) $
  else $
  ;//Get sub dir's of this dir
  addPath = expand_path('+' + pathString, COUNT=dirCount)

 ;//Tokenize the dirs to add
 addPathSArr = str_sep(addPath, pathDelim)

 ;//Add, but make sure not adding duplicate paths
 newPath = !path
 currentPathSArr = str_sep(newPath, pathDelim)
 for i=0, n_elements(addPathSArr)-1 do begin
  if (where(strlowcase(addPathSArr[i]) EQ strlowcase(currentPathSArr))
EQ -1)[0] then begin
   ;//Add to front or back?
   if n_elements(append) EQ 0 then $
    newPath = addPathSArr[i] + pathDelim + newPath $
   else $
    newPath = newPath + pathDelim + addPathSArr[i]
  endif
 endfor
 ;////////////////////////////////

 return, newPath
end;//module tbAddToPath
;////////////////////////////////
"Markus Feldt" <mfeldt@mpia-hd.mpg.de> wrote in message
389980B4.1620E411@mpia-hd.mpg.de">news:389980B4.1620E411@mpia-hd.mpg.de...
> Hi out there,
>
>   did anybody bother to write some helpers for handling pathnames under
> different OSs in IDL (something like "path_to_os") or so?  Something
> that replaces "/" bei "\" or ":" and appends ":" under MAC if needed? Or
> is there some implemented function in idl which allows accessing
> directory structures under differing OSs?  Just asking,  if not,  I'll
> write it myself...
>
>    Thanks
>
>            Markus
>
>
>
>
> --
>  /| '` |\  Markus Feldt                   Voice:      +49 6221 528 262
> |_| `' |_| Max-Planck-Institut            Fax:        +49 6221 528 246
>  --------  für Astronomie                 mailto:mfeldt@mpia-hd.mpg.de
> |  MPIA  | Königstuhl 17               http://life.mpia-hd.mpg.de:6001
> |________| D-69117 Heidelberg, Germany            Si, !asi es la vida!
>
>
>