<p>我试图让NTFS对象id在Python备份程序中使用。我有点不知所措,但设法创建了一个函数,返回。。。什么。在</p>
<pre><code>import sys
import win32file
import winioctlcon
def object_id(filename):
"""
NTFS OBJECT_ID
"""
fhandle = win32file.CreateFileW(
# FileName
filename,
# DesiredAccess
win32file.GENERIC_READ,
# ShareMode
win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
# SecurityAttributes
None,
# CreationDisposition
win32file.OPEN_EXISTING,
# FlagsAndAttributes
0
)
obj_id = win32file.DeviceIoControl(
# Device : PyHANDLE
# Handle to a file, device, or volume
fhandle,
# IoControlCode : int
# IOControl Code to use, from winioctlcon
winioctlcon.FSCTL_CREATE_OR_GET_OBJECT_ID,
# InBuffer : str/buffer
# The input data for the operation, can be None for some operations.
None,
# OutBuffer : int/buffer
# Size of the buffer to allocate for output, or a writeable buffer as
# returned by win32file::AllocateReadBuffer.
64,
# Overlapped=None : PyOVERLAPPED An overlapped object for async
# operations. Device handle must have been opened with
# FILE_FLAG_OVERLAPPED.
None
)
fhandle.Close()
return obj_id
</code></pre>
<p>调用此函数的一些示例输出是类似str的“↑·∟–kòπ◄Θδ%dΘπ╧hMêc▌╧J╧y╠┘π↑·∟–kòπ◄Θπ╧”。这对于我的程序来说是可以的,只要我备份的每个文件都是一致的。但我有没有做错什么可怕的事?理想情况下,我希望尽可能正确地实现这一点。在</p>