Notifications
Clear all

[Closed] relative folder paths

I have a project folder that contains a “scenes” folder and a “meshes” folder. I’m trying to write a script that will let me save a node from a file in the scenes folder to a new max file in the meshes folder. My problem is I can’t figure out how to tell it to save to a folder that is a level above the current folder. I can’t use the absolute file path becuase this will have to work from multiple project folders. Any help would be appreciated.

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

Posts: 0

You can parse the path and replace the string yourself.
Assuming the string to replace exists just once in the path name, you could say

fn switchPath thePath oldString newString = 
(
	theIndex = findString thePath oldString
	if theIndex != undefined then
		thePath = replace thePath theIndex oldString.count newString
	thePath	
)	

switchPath (getDir #export) "meshes" "scenes"

Since the above condition cannot be guaranteed, you could parse the path yourself and replace the last sub-directory instead.


fn removeLastDir thePath =
(
	theFS = filterString thePath "\\"
	theNewPath = ""
	for i = 1 to theFS.count-1 do theNewPath += theFS[i] + "\\"
	theNewPath
)

(removeLastDir (getDir #export)) + "scenes"

Hi, this may also work, but its not very UI friendly (i think)

the_file = (getdir #maxroot) + “…” + “/myfile.txt”
createfile the_file

the script will create a “myfile.txt” to whatever drive the 3dsmax folder is located.

Thanks for all the help guys! I got it working now.