Notifications
Clear all

[Closed] problem with openFile command

Hi guys,
I’ve found a problem while trying to script something not too difficult, i was wondering if anyone know what’s the best thing to do here…

so, whenever I use this line:

openNote = openFile "C:	est.txt" mode:"r"

works totally fine, but whenever i add that file on a mapped drive on the network, as in :

openNote = openFile "Z:	est.txt" mode:"r"

I get an undefined and it fails to open the file…

I’ve noticed that if I add a second slash as in: Z:\ est.txt works fine… is that the real case or am i doing something wront?

thanks a lot

13 Replies

read this chapter from the MXS help – String Literals

The backward slash is evaluating to an escape character, in this case a tab. You need to add the extra slash as you noticed, or use

openNote = openFile @"Z:	est.txt" mode:"r"

This is known as a verbatim string literal, it is read ‘as is’

 MZ1

“Z:” is not a network address, try to use a universal path:
//ComputerName/sharedfolder/…/yourfile
or
//IPAddress/sharedfolder/…/yourfile

 MZ1

Use this function to get UNC path:

pathConfig.convertPathToUnc "Z:	est.txt"

wow thanks so much for the replies guys, really helpful!

mmmm ok so is solved by adding the @ in front of the path…but what happens if this path is a variable? as in:


finalNoteFile = finalNoteFolder + "\\" + finalName +".txt"
openNote = openFile finalNoteFile mode:"r"

I believe is not working for the same reason i posted before…?

1 Reply
 lo1
(@lo1)
Joined: 11 months ago

Posts: 0

I work with mapped drives all the time, there should be no issue.

  • What is the value stored in finalNoteFolder?
  • What value does finalNoteFile evaluate to?

Btw, in your first example in this thread, the example targeting the C: drive should fail just the same as the Z: drive for the same reason, the failure here is the ’ ‘, not the drive letter. Are you sure it works?

I don’t have any mapped drives, so can’t really test this. However I always use pathconfig.appendpath to avoid any filename concatenation quirks. You can also check it actually exists before trying to open it.

finalNoteFile = pathconfig.appendpath finalNoteFolder (finalName +".txt")
if doesfileexist finalNoteFile  then openNote = openFile finalNoteFile mode:"r"

ok, i’ve narrowed down the problem a bit more and is a weird one…could anyone test thit for me please?
if i create a txt file on the harddrive by hand ( right click in windows, create txt file, i save it as FEO.INI and then i run this from maxscript:


databasePath = "P:\\3dsmax\\projects\\" 
fileToErase = ( databasePath + "feo.ini" )
deletefile fileToErase

returns TRUE and the file is erased, BUT if i create that same file, via maxscript with the
“createfile” command, the same code above returns false and the file can’t be erased…

is it only me?
thanks!

 lo1

try calling “close” on files you created or opened via maxscript before trying to delete them.

Page 1 / 2