ConsoleWrite(_GetAppropriatePath('C:\Program*\AutoIt*\AutoIt*.exe') & @CR)
ConsoleWrite(_GetAppropriatePath('C:\*\System??\user??.dll') & @CR)
ConsoleWrite(_GetAppropriatePath('C:\???????\explorer.exe') & @CR)
ConsoleWrite(_GetAppropriatePath('C:\*\Fon*\') & @CR)
Func _GetAppropriatePath($sPath, $iLevel = 0)
Local $hSearch, $tPath, $File, $Item, $Path, $Ret, $Dir = '', $Suf = '', $Result = ''
$tPath = DllStructCreate('wchar[1024]')
$Ret = DllCall('kernel32.dll', 'dword', 'GetFullPathNameW', 'wstr', $sPath, 'dword', 1024, 'ptr', DllStructGetPtr($tPath), 'ptr', 0)
If (@error) Or (Not $Ret[0]) Then
Return ''
EndIf
$sPath = DllStructGetData($tPath, 1)
If StringRight($sPath, 1) = '\' Then
$Dir = '\'
EndIf
$Item = StringSplit(StringRegExpReplace($sPath, '\\\Z', ''), '\')
Select
Case $iLevel + 1 = $Item[0]
If FileExists($sPath) Then
Return $sPath
Else
Return ''
EndIf
Case $iLevel + 1 > $Item[0]
Return ''
EndSelect
For $i = 1 To $iLevel + 1
$Result &= $Item[$i] & '\'
Next
$Result = StringRegExpReplace($Result, '\\\Z', '')
If Not FileExists($Result) Then
Return ''
EndIf
$hSearch = FileFindFirstFile($Result & '\*')
If $hSearch = -1 Then
Return ''
EndIf
For $i = $iLevel + 3 To $Item[0]
$Suf &= '\' & $Item[$i]
Next
While 1
$File = FileFindNextFile($hSearch)
If @error Then
$Result = ''
ExitLoop
EndIf
If (Not @extended) And ($Dir) And ($iLevel + 2 = $Item[0]) Then
ContinueLoop
EndIf
$Ret = DllCall('shlwapi.dll', 'int', 'PathMatchSpecW', 'wstr', $File, 'wstr', $Item[$iLevel + 2])
If (Not @error) And ($Ret[0]) Then
$Path = _GetAppropriatePath($Result & '\' & $File & $Suf & $Dir, $iLevel + 1)
If $Path Then
$Result = $Path
ExitLoop
EndIf
EndIf
WEnd
FileClose($hSearch)
Return $Result
EndFunc ;==>_GetAppropriatePath