← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #232844]: Can Sikuli search the sub-folders to find screenshots?

 

Question #232844 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/232844

RaiMan posted a new comment:
Uuups, that looks really strange ;-)

again pythonized:

assuming my_screenshot_path is a global variable:

def set_screenshot_path(path):
    global my_screenshot_path
    my_screenshot_path = repr(path).replace(r"\\", r"\").strip("'")


this reduces all eventually given \\ or \\\\ \\\\\\ or ... to \ 

But with one exception: \t or \n or \r in the path will be converted to real tab, newline or carriage-return characters by repr().
This is only a selection of common escaped characters 
(a bunch more: http://docs.python.org/2/reference/lexical_analysis.html#string-literals)

As long as all folder/subfolder names start with capital letters - no
problem.

So if you say, your users will copy the path string from the explorer to the script, then you might have this problem.
On the other hand, if they do so, the string will never contain \\ internally, because one would have to say either

"c:\\\\Test\\\\Folder"

or

r"c:\\Test\\Folder"

So if you do not tell them, they would not do it and someone who knows
Python will not do it either.

So if you tell them: copy the path from explorer to the script and have
it enclosed with " or '

you will get:
"c:\Test\Folder"

in the script, which will internally be
c:\Test\Folder

which is fine.

So if you want to be on the safe side with this concept (letting people
copy the path string into the script), then you have to take care for
the escape problem.

Depending on how they might use your scripts, it might be a solution, to
get the path as a runtime command line parameter.

Still the easiest way is to use some rule for the screen-shot-path based
on the location of the script (again easiest: same folder as the script)

BTW: getBundlePath() in fact returns a String and does not need a str()
and this might only be complained by Eclipse at edit time, since it does
not know the method getBundlePath().

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.