Yashied Posted September 17, 2011 Posted September 17, 2011 (edited) A simple function which returns the first matching path for a specified wildcard, if exists. UNC paths are not supported. The name of the drive must be specified obviously. expandcollapse popupConsoleWrite(_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 Edited December 22, 2013 by Yashied Deye 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now