﻿#include <APIFilesConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>

#Region *** ReparsePoints (bei einem deutschen Windows) ***
Global $sPath = @UserProfileDir & '\Eigene Dateien'
;~ Global $sPath = @UserProfileDir & '\Anwendungsdaten'
;~ Global $sPath = 'c:\programme'
;~ Global $sPath = 'c:\Dokumente und Einstellungen'
#EndRegion *** ReparsePoints ***

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPath = ' & $sPath & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Global $aFiles = _FileListToArray($sPath) ; <- hier kommt die Fehlermeldung Nr. 4 ("No File(s) Found")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFiles = ' & $aFiles & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;~ _ArrayDisplay($aFiles)

Global $iAttr = _WinAPI_GetFileAttributes($sPath)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iAttr = ' & $iAttr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Global $bReparsePoint = BitAND($iAttr, $FILE_ATTRIBUTE_REPARSE_POINT) == $FILE_ATTRIBUTE_REPARSE_POINT
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bReparsePoint = ' & $bReparsePoint & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Global $sTargetPath = _ReparsePointGetTarget($sPath)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sTargetPath = ' & $sTargetPath & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Global $aFiles = _FileListToArray($sTargetPath)
_ArrayDisplay($aFiles, 'mit TargetPath')

Func _ReparsePointGetTarget($sPath)
	Local $tGUID, $hFile, $sPathName
	$tGUID = _WinAPI_CreateObjectID($sPath)
	$hFile = _WinAPI_OpenFileById($sPath, $tGUID, 0, BitOR($FILE_SHARE_DELETE, $FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_OPEN_REPARSE_POINT)
	If $hFile = 0 Then Return
	$sPathName = _WinAPI_GetFinalPathNameByHandleEx($hFile)
	_WinAPI_CloseHandle($hFile)
	Return $sPathName
EndFunc
