;docformat='rst' ;+ ; Normalize a string assumed to be a path by converting any backslashes ; (from a Windows path) to slashes (unix), then replacing consecutive ; slashes with a single slash. ; Finally the the slashes are replaced by whatever is returned by the ; IDL operating system dependent function "path_sep()" ; ; :Author: ; Chris Jeppesen ; ;- ;+ ; :Params: ; p_: in, required, type=string ; a path to be normalized ;- ;+ ; :Examples: ; path = normalize_path('/crazy\path//with///problems') ;- function normalize_path,p_ p=p_ ;keep track if the original had a / at the beginning begin_slash=(strmid(p,0,1) eq '/') ;Turn all folder separators to unix convention p=strrep(p,'\\','/',/regex) ;Remove duplicates (converts even numbers of / to a single /) p=strrep(p,'//','/',/regex) ;Remove duplicates (Do it again in case there were an odd number of /) p=strrep(p,'//','/',/regex) ;Turn all folder separators to local convention p=strrep(p,'/',path_sep(),/regex) ;put beginning slash back on (code above invariably strips it off) if begin_slash then p='/'+p return,p end