Forum Discussion

rmnrdi's avatar
rmnrdi
Contributor
7 years ago

Fixing javascript path issues

I have a function that gets a path from the registry.

 

It is in the form C:\folder\folder\folder\

 

Unfortunately, this won't work in my javascript functions. It needs to be of the form

C:\\folder\\folder\\folder\\

 

Is there a canned way to handle this, or do I have to write something convert this?

  •  

    ACtually, it depends upon how you use it.  True, in JavaScript, if you want to hardcode a string to have the \ character, you need to double it.  But that isn't necessarily the case if you are reading text out of another location.  For example, Project.Path returns the location of the project file as a string.  This includes \ characters.  But I can use Project.Path in a filepath parameter without having to do any replacement.

     

    Can you share the code that you're attempting to use the registry path from? It would be good to see how you're trying to use it... perhaps there's a better way that wouldn't have that problem.

     

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

     

    ACtually, it depends upon how you use it.  True, in JavaScript, if you want to hardcode a string to have the \ character, you need to double it.  But that isn't necessarily the case if you are reading text out of another location.  For example, Project.Path returns the location of the project file as a string.  This includes \ characters.  But I can use Project.Path in a filepath parameter without having to do any replacement.

     

    Can you share the code that you're attempting to use the registry path from? It would be good to see how you're trying to use it... perhaps there's a better way that wouldn't have that problem.

     

     

    • rmnrdi's avatar
      rmnrdi
      Contributor

      Hi Robert,

       

      After looking at it, it was only the log that was showing the single \.

       

      I should have checked via debugger first. It was correct.

       

      I've been converting from DelphiScript to JavaScript and I'm still gettin used to the \\ thing

       

      Thanks