Notifications
Clear all

[Closed] doesFileExist Test

say for example i have this folder in drive “D: est_folder”

now i run the script:
doesFileExist “d:[b]t[/b]est_folder” –would return false

but if i change the code to this:
doesFileExist “d:[b]T[/b]est_folder” –would return true

now, in the end, i found out (reading through the helpfile) that meant TAB…

and also a little later after that (again reading through the helpfile), using / would cause lesser anomalies as maxscript can read “D:/test_folder” no problem.

I was just hoping that in later versions of maxscript, whenever we use functions like getsavepath, getfiles, getdirectories and so on, an option to convert it to the “slash” format automatically would be great. (or automatically convert contradicting small letters to capital letters)

just my two centavos…

7 Replies

String literals are well documented in the help file and work any place you use strings in MAXScript. Changing it in a future version would introduce ambiguity in how things work and would potentially break any existing scripts that use string literals correctly.

What will fix your problem is the fact that while ” ” is a <tab> character in a string, “\” is a \ character in a string.

Your code should be written either as: doesFileExist “d:\test_folder”
[font=Verdana]or: doesFileExist “d:/test_folder”
[/font]

many thanks
right now im writing out a function to convert [b][/b] in strings to /.
It seems like the right thing to do.

and yup, the maxscript helpfile rocks, i love the examples they added.

ok, got it working… just in case anyone needs it… although its pretty simple to write.


fn convertStringToSlash txt =
 (
 local txt
 if txt != undefined do
  (
  txtcount = txt.count  
  for i in 1 to txtcount do
   (
   if (matchpattern txt[i] pattern:"\\" ignorecase:true)  do
	(	   
	txt = replace txt i 1 "/"
	)
   )
  )
 return txt
 )

Just an additional note:

The ” ” problem only arises when you are passing the script through the MAXScript parser (either using the string inside a script, through the Execute function, ReadValue function, or evaluating in the Listener with numpad Enter).
If you have an editText UI control and the user has entered in it
“c: emp est.txt”, using this string in your functions will NOT cause a problem, because the string will not be parsed by MAXScript but used As Is. Same applies to strings that come from functions like getSaveFileName, getOpenFileName, getSavePath etc. The strings returned by these functions, even if containing single backslashes, will be valid.

This is why there is no necessity to convert backslashes to slashes most of the time.
I personally usually use “/” in my code to save myself some time…

thanks bobo, ill keep that in mind, your wisdom is always valuable. i was beginning to worry that I’ll end up converting everyting everytime…

and oh, I think Ive heard somewhere that discreet was updating the maxscript helpfile… im not sure, but if so, is it possible to grab a copy of it from thier site?

jefflim

The day the 7.5 update ships to subscription members, the updated MAXScript Reference will be available for public download from a Discreet/AMAE/whatever web page. I am still polishing it right now.

thanks Bobo, looking forward to it.