Notifications
Clear all

[Closed] please help , reading string with "c:\releases\proyect" problem with "\r" in name

am using this

     if (ss = openfile "C:\\TEMP\\paths.txt") != undefined then
         (
         paths.items = execute (readline ss as string)
         close ss
         )
     else

the problem is the name of the path, because it have “\r” in the path name, so when a read this i have a different name without the “\r” and the same with the paths that have /p or /n

I know that having “c:\proyect\releases” work, but how can I write the path with that format and read this but showing as ““c:\proyect\releases” to the user

is there any form to read a string without take in count special characters

please help with this guys.

thanks

8 Replies

i’m not sure why you are using execute if you are expecting each line to be a path string. based on your code i’d say that it should be:

if (ss = openfile @"C:\TEMP\paths.txt") != undefined then
  (
  	[b]paths.items = readline ss[/b]
  	close ss
  )

The above code is only reading the first line thought. If you want to read all lines into an array you could use dotnet like so:

allLines = (dotnetclass "System.IO.File").ReadAllLines @"C:	emp\paths.text"
1 Reply
(@ecarter)
Joined: 11 months ago

Posts: 0

i am ussing 3dsmax9

this line
if (ss = openfile @“C:\TEMP\paths.txt”) != undefined then

gave me and error
if I remove the @ it work but I have the same problem as the begining with the string

well iam storing the path on a dropdownlist, to select later by the user

Verbatim String Literals

NEW in 3ds Max 2008: Verbatim string literals added to MAXScript in 3ds Max 2008 are prefixed by the ‘@’ character and are NOT expanded even if containing backslash escape character sequences like ’ ‘, ’
’ or ‘\r’.

The syntax is

@”{<character>}+”

FOR EXAMPLE,

–the following verbatim string remains unchanged after evaluation:

thePath = @“g: emp
ewfolder\render”

“g: emp
ewfolder\render”

–while the following results in a

–scrambled string with tabs and new lines:

thePath = “g: emp
ewfolder\render”

“g: emp

ewfolder

ender”

where exactly are you coming across these escape characters that are causing the problem?
I can only think of 2 occasions where this might happen:

  1. you are writing the path string in code yourself in which case you should use the double backslash or the forward slash
  2. you are executing a string containing escape characters. As a general rule, execute should be avoided as much as possible since it can be slow and there’s usually a much more elegant way of doing things.
1 Reply
(@ecarter)
Joined: 11 months ago

Posts: 0

my problem is that I write the paths of export files to a txt file, and then read this info to a dropdownlist, so the user can select the exported paths that he used to export again without searching for the path again.

my big problem now is that I’m using 3dsmax9 and the newest version’s have useful metod to format this type of string like the “@”


fn xReplace st = -- replaces "\" by "/" on a given string
(
	n=""
	for i = 1 to st.count do n+=if st[i]=="\\" then "/" else st[i]
	n
) 

		
if (ss = openfile "C:\\TEMP\\paths.txt") != undefined then
(
paths.items = execute (xReplace(readline ss as string))
close ss
)
else

.......

1 Reply
(@ecarter)
Joined: 11 months ago

Posts: 0

You solve may problem, because iam using 3dsmax 9, thanks too much for having some time to fix my problem

and thanks to everybody here.

sorry to be so irritating, but i have a new problem, and i have a solution but I can´t implement it.

with your code the data is correct but with "/" instead of "\" , that is ok, for export and everything, but for "getSavePath caption:"Select directory" initialDir:path.selected"

that is not working, the path with the "\"  at initial dir, work well and the dialog send me to the selected path, but with the "/" the dialog allways send me to the desktop.

i think that using the funcition xReplace to replace the "\" for "\\" maybe could work, because the path

"c:\\releases\	emp\\" is ok for 3dsmax and "initialdir"

this is my code, and.... don´t work 

    	on NPath pressed do
    	(
    	
    		fn xReplace st = -- replaces "\" by "/" on a given string
    		(
    			n=""
    			for i = 1 to st.count do n+=if st[i]=="\" then "\\" else st[i]
    			n
    		) 
    			
    			target = getSavePath caption:"Select directory" initialDir:path.selected
    			if target == undefined do return false
    				path.items= append path.items (target as string)
    				path.selection = path.items.count
    				
    	  
    			if (ss = createFile "C:\\TEMP\\paths.txt") != undefined do
    				(
    				xReplace (with printAllElements on path.items as string)
    				format "%
" (with printAllElements on path.items as string) to:ss
    				flush ss
    				close ss
    				)
    	
    	)