3

I'm having a text file in Resource folder and my robot script in sibling folder namely Test, I need to use the relative path otherwise I need to specify the path explicitly once I changed the project location.

TEST PROJECT (Root folder)
|
|_____ Resource (folder)
|       |_____ MyProfile.txt
|       |_____ MyPicture.jpg
|
|_____ Test (folder)
        |_____ MyTest.robot

I want to access the MyProfile.txt in MyTest.robot using relative reference instead of absolute path.

Kindly assist me.

3 Answers 3

10

We can give the Relative path by using the following approach

${CURDIR}${/}..\\Resource\\MyProfile.txt

The ${CURDIR} will return the path of where you are using this code, then we need to back track using the navigation operator ..\\

But if you use ${EXECDIR} will return the path of the file is executing.

${EXECDIR}${/}..\\Resource\\MyProfile.txt

Here the code and execution both are handled in a single file, so both the code will give you the appropriate location of MyProfile.txt

Sign up to request clarification or add additional context in comments.

Comments

0

or another way, you may add the project root folder to the sys.path. it will search up the referenced resources from the root folder.

Comments

0

you can try something like that

../../Resources/MyProfile.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.