0

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

Marcus Scharf
  • 55
  • 1
  • 1
  • 5

1 Answers1

1

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 PyCharmcontext. 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

RaiMan
  • 1,088
  • 8
  • 13
  • Thanks for clarifying the nameing convention of the file-folders. The: `os.path(getBundlePath()).basename()` gives me an error The error: **AttributeError ( 'unicode' object has no attribute 'basename' )** – Marcus Scharf Mar 16 '22 at 10:34
  • Oh, figured it out. I just said `os.path.basename(getBundlePath())` and got the output you predicted. – Marcus Scharf Mar 16 '22 at 10:44