Enumerates the first stream with a ::$DATA stream type in the specified file or directory
#include <WinAPIFiles.au3>
_WinAPI_FindFirstStream ( $sFilePath, $tData )
$sFilePath | The fully-qualified file name. |
$tData | A $tagWIN32_FIND_STREAM_DATA structure or a pointer to it that receives information about the stream. |
Success: | The search handle. |
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the system error code. |
This function function opens a search handle and returns information about the first stream in the specified file or directory.
For files, this is always the default data stream, "::$DATA".
After the search handle has been established, use it in the _WinAPI_FindNextStream() function to search for other streams in the specified file or directory.
If the function fails because no streams can be found, the @extended flag will contain ERROR_HANDLE_EOF (38) system error code.
When the search handle is no longer needed, it should be closed using the _WinAPI_FindClose() function.
This function requires Windows Vista or later.
_WinAPI_FindClose, _WinAPI_FindNextStream
Search FindFirstStreamW in MSDN Library.
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
#include <WinAPIMem.au3>
#include <WinAPIMisc.au3>
#include <WinAPIShPath.au3>
_Example()
Func _Example()
Local Const $sTempFile = @TempDir & '\Test.txt'
; Check NTFS file system
If StringCompare(DriveGetFileSystem(_WinAPI_PathStripToRoot($sTempFile)), 'NTFS') Then
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'The file must be on an NTFS file system volume.')
Exit
EndIf
Local $sName, $iBytes, $pData, $hFile
; Create text file with three alternative streams named AS1, AS2, and AS3 respectively
For $i = 0 To 3
If $i Then
$pData = _WinAPI_CreateString('Alternative stream ' & $i)
$sName = ':AS' & $i
Else
$pData = _WinAPI_CreateString('Main stream')
$sName = ''
EndIf
$hFile = _WinAPI_CreateFile($sTempFile & $sName, 1, 4)
_WinAPI_WriteFile($hFile, $pData, _WinAPI_GetMemorySize($pData) - 2, $iBytes)
_WinAPI_CloseHandle($hFile)
_WinAPI_FreeMemory($pData)
Next
; Enumerate all existing streams in the file and read text data from each stream
$pData = _WinAPI_CreateBuffer(1024)
Local $tFSD = DllStructCreate($tagWIN32_FIND_STREAM_DATA)
Local $hSearch = _WinAPI_FindFirstStream($sTempFile, $tFSD)
Local $iSize
While Not @error
$sName = DllStructGetData($tFSD, 'StreamName')
$iSize = DllStructGetData($tFSD, 'StreamSize')
$hFile = _WinAPI_CreateFile($sTempFile & $sName, 2, 2, 6)
_WinAPI_ReadFile($hFile, $pData, $iSize, $iBytes)
_WinAPI_CloseHandle($hFile)
ConsoleWrite(StringFormat('%10s (%s bytes) - %s', $sName, $iSize, _WinAPI_GetString($pData)) & @CRLF)
_WinAPI_FindNextStream($hSearch, $tFSD)
WEnd
Switch @extended
Case 38 ; ERROR_HANDLE_EOF
Case Else
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), @extended, _WinAPI_GetErrorMessage(@extended))
EndSwitch
_WinAPI_FindClose($hSearch)
_WinAPI_FreeMemory($pData)
FileDelete($sTempFile)
EndFunc ;==>_Example