sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #47938
[Question #671390]: How to build a path within an existing directory
New question #671390 on Sikuli:
https://answers.launchpad.net/sikuli/+question/671390
Note: I am new to Python & SikuliX
I am looking at using SikuliX as an automation replacement for an existing script that I have in HPE UFT.
One of the things I am struggling with is how to create directory structures inside existing folders.
For example, let's say that I have a base folder called "C:\Screenshots" for the storing of screenshots from various applications.
In UFT, I have a VBScript function that checks to see if the full path exists - if it doesn't, it creates it:
(Note that the application name and the test type are determined elsewhere in the script on the fly)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
FullPath = "C:\Screenshots\MyApp\08-05-18\ProdTest"
Private Function BuildFullPath(ByVal FullPath)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(FullPath) Then
BuildFullPath objFSO.GetParentFolderName(FullPath)
objFSO.CreateFolder FullPath
End If
Set objFSO = Nothing
End Function
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The above function will iterate through folder structure, and if any portion of the path doesn't exist, it will create it.
I tried the below code in SIkuliX.
(The folder structure of "C:\Screenshots\Sikuli_Test" already exists.)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import os
FullPath = "C:\Screenshots\Sikuli_Test\08-05-18\ProdTest"
os.mkdir(FullPath)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
SikuliX returned the following error:
OSError: (17, 'File exists', 'c:\\screenshots\\sikuli_test'
Part of the challenge is that the script will not always know how deep the given folder structure will already exist. The script will need to determine this, and then create the folders as needed.
The VBScript function outlined above this simple & fast in its loop with the FileSystemObject. Is there a way to do something similar within Python & SikuliX?
Side question: can Python discern between a directory and a file? The error returned leads me to believe that it is confusing a an existing folder as an existing file.
Thanks in advance,
Ron Turrentine
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.