LaidlawFX Posted May 5, 2014 Share Posted May 5, 2014 (edited) 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 May 5, 2014 by LaidlawFX Quote Link to comment Share on other sites More sharing options...
edward Posted May 5, 2014 Share Posted May 5, 2014 Forward slash is not an escape character. Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted May 5, 2014 Author Share Posted May 5, 2014 Sorry said it backwards backslash is the escape character... Quote Link to comment Share on other sites More sharing options...
pezetko Posted May 6, 2014 Share Posted May 6, 2014 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('\\','/')")` Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted May 6, 2014 Author Share Posted May 6, 2014 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 Quote Link to comment Share on other sites More sharing options...
pezetko Posted May 6, 2014 Share Posted May 6, 2014 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 Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted May 6, 2014 Share Posted May 6, 2014 (edited) 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 May 6, 2014 by mantragora Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted May 13, 2014 Author Share Posted May 13, 2014 Thanks guys. Stuff worked out, well. Now for the big adventure, the full python conversion... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.