How to read windows file properties?

Asked by Shawn Robertson

I am trying to read windows file properties and reading on python options it seems that some people are using extensions called PYWIN32 ??

im having difficulty translating or interpreting the syntax into something I can use in Sikuli mainly with the whole import part first.

This was one of the examples i saw that I wanted to try but couldn't:

"from win32com.client import Dispatch

ver_parser = Dispatch('Scripting.FileSystemObject')
info = ver_parser.GetFileVersion(path)

if info == 'No Version Information Available':
    info = None"

maybe i'm going about this wrong?

Instead of using:
subprocess.Popen('explorer os.path.join('c:', os.sep, 'tssmoketest', tsVersion)') to open an explore window and then using a whole bunch of scrolls/finds and right clicks to get to properties...

i was hoping to find some way to just go directly to the file itself and read/print certain attributes such as:

value in the Version tab
if a digital signature is present etc..

things like that.

for now i'm using the right click scroll options to get by but id like a more direct cleaner method if possible.

Thanks in advance!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Shawn Robertson (shawn-robertson) said :
#1

Or better yet Id love to use this one which is supposed to just trigger the Property window that appears when you right click a file and choose properties.

But when i use this code below Sikuli tells me "no module names wintypes"

import time
import ctypes
import ctypes.wintypes

SEE_MASK_NOCLOSEPROCESS = 0x00000040
SEE_MASK_INVOKEIDLIST = 0x0000000C

class SHELLEXECUTEINFO(ctypes.Structure):
    _fields_ = (
        ("cbSize",ctypes.wintypes.DWORD),
        ("fMask",ctypes.c_ulong),
        ("hwnd",ctypes.wintypes.HANDLE),
        ("lpVerb",ctypes.c_char_p),
        ("lpFile",ctypes.c_char_p),
        ("lpParameters",ctypes.c_char_p),
        ("lpDirectory",ctypes.c_char_p),
        ("nShow",ctypes.c_int),
        ("hInstApp",ctypes.wintypes.HINSTANCE),
        ("lpIDList",ctypes.c_void_p),
        ("lpClass",ctypes.c_char_p),
        ("hKeyClass",ctypes.wintypes.HKEY),
        ("dwHotKey",ctypes.wintypes.DWORD),
        ("hIconOrMonitor",ctypes.wintypes.HANDLE),
        ("hProcess",ctypes.wintypes.HANDLE),
    )

ShellExecuteEx = ctypes.windll.shell32.ShellExecuteEx
ShellExecuteEx.restype = ctypes.wintypes.BOOL

sei = SHELLEXECUTEINFO()
sei.cbSize = ctypes.sizeof(sei)
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST
sei.lpVerb = "properties"
sei.lpFile = "C:\\Desktop\\test.txt"
sei.nShow = 1
ShellExecuteEx(ctypes.byref(sei))
time.sleep(5)

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

Actually forget the above comment.

Ideally I need to read/stream in specific elements and assert them.

I need to stream/read File version from the version tab and verify that its proper against supplied variable value.

i did write a quick little:

SCR0 = Screen(0)
SCR1 = Screen(1)

type("timeslip.exe")
wait(3)
keyDown(Key.ALT)
type(Key.ENTER)
keyUp(Key.ALT)
if SCR0.exists("Timeslip-1.png") or SCR1.exists("Timeslip-1.png"):
    wait(1)
type(Key.TAB, KeyModifier.CTRL)
type(Key.TAB, KeyModifier.CTRL)
type(Key.TAB, KeyModifier.CTRL)
type(Key.TAB, KeyModifier.CTRL)
wait(1)
assert exists(version.png)

but this wont work because the version will always change every time i perform an installation and I cant keep changing the png file so it looks like i need to stream in the correct value and compare i believe.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

allready had a look at the tons of Python file features to directly access the file system??
http://docs.python.org/2.6/library/filesys.html#file-and-directory-access

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

Thanks Raiman, on a side note.... how does Sikuli keep up to date with the latest stable builds of Python? right now there is python 3.3 stable but what is Sikuli based on currently? What happens when 3.4 comes out, does Sikuli test with the latest build and release another build as well?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Sikuli utilizes Python language and the interpreter used internally is Jython 2.5.x (latest stable 2.5.3, is in the new version), which means, we are still on language level Python 2.5. Jython is a Java implementation of the Python interpreter and the standard library.

There is a beta Jython 2.7, that will implement the language level 2.7. There are no signs of level 3.x yet.

Can you help with this problem?

Provide an answer of your own, or ask Shawn Robertson for more information if necessary.

To post a message you must log in.