How to create a valid pathname on Windows

Asked by Shawn Robertson

Hi I have a script where I want the user to have a pop up window and input data that can be used later.

in my example I want the user to be prompted for the Version ie... "2014"

my goal with this one is that I call the Run command and paste a network path and the final folder is the version. we have folders for each version but the contents are always the same.

I'm using this in my script:

tsVersion = input("Enter your version ie.. 2013, 2014 etc:", "2014")

type("r", KeyModifier.WIN)
wait(Pattern("Typethenameo-1.png").similar(0.86), 60)
paste(r'\\XXXXXXXXX\TSStorage\Builds\\' +tsVersion)

the user is prompted for input and by default it has 2014 for now but they can certainly change to anything else like 2013, 2012 etc.

and my final path that is pasted into the run command is:

\\XXXXXXXXX\TSStorage\Builds\\2014

one of the paths later on that id like to paste is the exact same except it read this:

\\XXXXXXXXX\TSStorage\Builds\\2014\utilities

so i tried to put this in my script:

paste(r'\\XXXXXXXXX\TSStorage\Builds\\' +tsVersion 'utilities')

hoping that it would paste:
\\XXXXXXXXX\TSStorage\Builds\\2014\utilities

but instead it does not and errors out and says:

[error] Error message: SyntaxError: ("no viable alternative at input ''\\utilities''", ('C:\\Users\\SROBER~1\\AppData\\Local\\Temp\\sikuli-tmp7747038902081626523.py', 4, 54, "paste(r'\\\\gaqtsbuild01\\TSStorage\\Builds\\\\' +tsVersion '\\utilities')\n"))

is it even possible to do what i want to do? or does the Input variable always have to be the final item in the function?

thanks in advance, I have been reading a lot on stack overflow and python documentation but everything and everyone is always talking about raw_input() and still even with that they are really talking about what I want to do.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Handling with pathnames is best supported by os.path.
No need to fiddle around with \

import os
finaldir = os.path.join(r"\\XXXXXXXXX", "TSStorage", "Builds", tsVersion, "utilities")
paste(finaldir)

or if you want to make it your way:
finaldir = r"\\XXXXXXXXX\TSStorage\Builds\" + tsVersion + r"\utilities"
paste(finaldir)

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#3

thanks so much Raiman, this worked perfectly!