I want to get a number from the filepath of the current file in Sikuli - Jython
I have a python example of what i'm trying to achive.
In the example the path is: C:\PycharmProjects\TestingPython\TestScripts\TestScript_3.sikuli\TestScript.py
import os
PointerLeft = "Script_"
PointerRight = ".sikuli"
FilePath = os.path.dirname(os.path.abspath(__file__))
NumberIWant = FilePath[FilePath.index(PointerLeft) + len(PointerLeft):FilePath.index(PointerRight)]
print(NumberIWant)
So what i want to get is the number 3. In python the example above works, but I cant use the __file__
ref in Sikulix. Nor does the split of the string work, so even if I get the string of the path, I still have to get the number.
Any help and/or ideas is greatly appreciated
Important:
the .py
file in a .sikuli
folder must have the same name
hence in your case: ...\TestScript_3.sikuli\TestScript_3.py
It looks like you are trying to run your stuff in the PyCharm
context. If you do not run the script in the SikuliX IDE, you have to add from sikuli import *
even to the main script.
To get the file path of the script use getBundlePath()
.
Then os.path(getBundlePath()).basename()
will result to the string "TestScript_3.sikuli"
.
RaiMan from SikuliX