Notifications
Clear all

[Closed] Paths: slashes to backslashes Issue? Or what?

Hi,

I wrote this function to return paths as backslashes

fn setBackslashes _STRING = (
	arr = #()
	for i=1 to _STRING.count do (
		if _STRING[i] == "/" then (
			append arr "\\"
		) else (
			append arr _STRING[i]
		)
	)
	newString = ""
	for j=1 to arr.count do (
		newString += arr[j]
	)
	newString
)

But it seems to be failing while I use this to shellLaunch() network paths.

At first thought that this is an issue with shellLaunch itself, but now Im not sure.

So this is not working:

shellLaunch "explorer" (setBackslashes SomeNetworkPath)

But once I copy manually the string generated by

setBackslashes SomeNetworkPath

and then

shellLaunch "explorer" JustCopiedString

it works fine. The same happens here:

projROOT_path = "//SomeNetworkComputer"
p_local = setBackslashes projROOT_path
p_network = "\\" + (setBackslashes projROOT_path)
doesFileExist p_local
-- true
doesFileExist p_network
-- false

but once I copy the p_network manually and run

doesFileExist p_network_JustCopiedManually
-- true

It works great.

This completely has no sense. Because both strings are identically, but when run

p_network_JustCopiedManually == p_network
-- false

So I guess the issue is my weird function setBackslashes()?

3 Replies
1 Reply
(@aaandres)
Joined: 1 year ago

Posts: 0

DenisT method is of course the better one.
The problem with your function is one of these two ones:

  • You should put 4 backslashs “\\” as each time you evaluate the string, the “” is taken as an escape character.
  • Your network name starts by an ‘escapable’ character (n, r, t…) so the backslash works as the escape for this characters and so the string changes when it’s evaluated.

By the way, in few days your function may be:
newString = (_From _STRING).Replace#(“/”,”\”)

I hope by the end of this week i’ll publish my ‘maxLINQ’ script that can make these things quite easier.

if you want just change slashes to backslashes in the string (path) use pathConfig.resolvePathSymbols

Thank you so much. I thought that there may be something like that, but max help is such a mess…