VirtualBox

Ticket #14464: find_data.py

File find_data.py, 1.1 KB (added by Matt Hopkins, 9 years ago)

find_data.py

Line 
1import sys
2import ctypes
3from ctypes.wintypes import WIN32_FIND_DATAW as WIN32_FIND_DATA
4
5
6_INVALID_HANDLE_VALUE = -1
7_FindFirstFile = ctypes.windll.kernel32.FindFirstFileW
8_FindNextFile = ctypes.windll.kernel32.FindNextFileW
9_FindClose = ctypes.windll.kernel32.FindClose
10_GetLastError = ctypes.windll.kernel32.GetLastError
11FILE_ATTRIBUTE_REPARSE_POINT = 0x0400
12
13def main():
14 if len(sys.argv) != 2:
15 print u"Usage: %s [target_file]" % sys.argv[0]
16 return
17
18 target = unicode(sys.argv[1], sys.getfilesystemencoding())
19
20 print u"Target file is %s" % target
21
22 wfd = WIN32_FIND_DATA()
23
24 handle = _FindFirstFile(target, ctypes.byref(wfd))
25
26 if handle != _INVALID_HANDLE_VALUE:
27 print u"Found file: %s" % wfd.cFileName
28 print u"Reparse point: %s" % (wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
29 print u"Attributes: %s" % wfd.dwFileAttributes
30 while _FindNextFile(handle, ctypes.byref(wfd)):
31 print u"Found file: %s" % wfd.cFileName
32 else:
33 print u"FindFirstFile failed (%d)" % _GetLastError()
34
35 _FindClose(handle)
36
37
38if __name__ == '__main__':
39 main()

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy