Jump to content

Convert - Reverse - Flip Backslash \ to a Forwardslash / hscript


LaidlawFX

Recommended Posts

Hello,

 

I'm using Hscript for some paths in Houdini and some of the global variables on windows are coming in as Backslashes \ and for some uses I need them as Forwardslashes / in Houdini and \ backslashes outside of Houdini.

 

Is there a way to change the forward slash to a back slash? Unfortunately backslash is an escape character...

http://www.sidefx.com/docs/houdini13.0/commands/_guide#idm47064707811440

 

Example

C:\Windows

needs to be

C:/Windows

 

As silly as this is in order to convert the other way this is the method i have, but doesn't work in the reverse

`strreplace(strreplace("C:\Windows","/","\ ")," ","")`

 

Thanks

-Ben

 

Edit: mistyped forward instead of back

Edited by LaidlawFX
Link to comment
Share on other sites

For forward to backward slash is this conversion a bit simplier:

echo `strreplace("/project/project.hip", "/", "\\")`

For other direction I'm more comfortable with python:

echo `pythonexprs("str('c:\project\project.hip').replace('\\','/')")`
Link to comment
Share on other sites

Hey Petr,

Thanks for the help, one last question for this then, if you don't mind.

 

Would you know why something like this wouldn't evaluate?

echo `pythonexprs("str(expandString('chs("mypath")')).replace('\\','/')")`

with chs("mypath") == c:\project\project.hip

 

I'm at the unfortunate situation to be half between languages at this point.

 

Thanks again

Link to comment
Share on other sites

You are welcome, for python it needs to be:

hou.expandString('`chs("mypath")`')

(hou is Houdini python module, and there are extra backticks around chs())
But this hscript(python(hscript)) seems to be a little bit complicated for evaluation.

Once in python stay in python:

echo `pythonexprs("str(hou.parm('/obj/geo1/null1/mypath').eval()).replace('\\','/')")`

Where mypath is string parameter on the null1 node.
For evaluating on the same node you can use something like this in hscript expression:

`(pythonexprs("str(hou.pwd().parm('mypath').eval()).replace('\\','/')"))`

Where pwd() return current node.
 

 

python_hscript.hip

Link to comment
Share on other sites

Guest mantragora

Remember that you can also use

>>> import os
>>> os.path.normpath("C:\\\Windows/System32//oobe\/\/\/info\\\\//////backgounds")
'C:\\Windows\\System32\\oobe\\info\\backgrounds'


to fix mixed slashes problem and always get "\\" from environment variables or any path. Edited by mantragora
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...