Relative path from project folder

Hi I want to know relative path from toe file.
I know project.folder but is there any script to parent folder from toe file?
I want to know path from
projects\test\test.toe
to
projects\assets\images\texture.jpg
for example.
Thanks.

The python library os.path has a function called relpath. So something like this:

import os.path
print(os.path.relpath('projects\\assets\\images\\texture.jpg', 'projects\\test'))

The second argument is optional if you just want to know from the current working folder, which is the folder your .toe file is in

(corrected to use double slashes…)

Thanks Ivan.
I run the script then text port showed this.
I would like to write python on MovieFileIn TOP “file” instead of absolute path so as not to miss the file when drive letter was changed.

Ah, sorry you need to use double slashes!

import os.path
print(os.path.relpath('projects\\assets\\images\\texture.jpg', 'projects\\test'))
1 Like

Thanks Ivan!