doestergaard Posted May 27, 2014 Share Posted May 27, 2014 Im trying to get just the full path of the directories that contains a specific file type. My problem is, that get the same folder listed many times, because it obvious finds more files with the specific file type Is it possible to output just the directory from where the inf file was found? For example "C:driversHP-Webcam" contains 8 inf files - the ouput would show 8x "C:driversHP-Webcamfilename.inf" I just need it to output it once to the array and the same for every folder within "c:drivers" and just get: c:drivershp-webcamx64 c:driverscardreader c:driversgraphicsx64 c:driversaudio c:driverssmbus_controller And so on... I have tried the following code which was taken from another post, but outputs the same directory several times. expandcollapse popup#include <Array.au3> $folderarray = _FileListToArray_Recursive("C:\drivers\", "*.inf", 1, 2, True) _ArrayDisplay($folderarray) ;=============================================================================== ; $iRetItemType: 0 = Files and folders, 1 = Files only, 2 = Folders only ; $iRetPathType: 0 = Filename only, 1 = Path relative to $sPath, 2 = Full path/filename Func _FileListToArray_Recursive($sPath, $sFilter= "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False) Local $sRet = "", $sRetPath = "" $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") If Not FileExists($sPath) Then Return SetError(1, 1, "") If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "") $sPath &= "\|" $sOrigPathLen = StringLen($sPath) - 1 While $sPath $sCurrPathLen = StringInStr($sPath, "|") - 1 $sCurrPath = StringLeft($sPath, $sCurrPathLen) $search = FileFindFirstFile($sCurrPath & $sFilter) If @error Then $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1) ContinueLoop EndIf Switch $iRetPathType Case 1 ; relative path $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen) Case 2 ; full path $sRetPath = $sCurrPath EndSwitch While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If ($iRetItemType + @extended = 2) Then ContinueLoop $sRet &= $sRetPath & $file & "|" WEnd FileClose($search) If $bRecursive Then $hSearch = FileFindFirstFile($sCurrPath & "*") While 1 $file = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then $sPath &= $sCurrPath & $file & "\|" WEnd FileClose($hSearch) EndIf $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1) WEnd If Not $sRet Then Return SetError(4, 4, "") Return StringSplit(StringTrimRight($sRet, 1), "|") EndFunc Thanks in advance! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 27, 2014 Share Posted May 27, 2014 You're defining it in the Function itself, which may override what you pass to it. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 27, 2014 Moderators Share Posted May 27, 2014 doestergaard,Use _ArrayUnique on the array holding the returned list with duplicates - that way you only get each array listed once. You will of course need to remove the file name from the returned paths so that you only store the folder name itself, but that is trivial. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 27, 2014 Share Posted May 27, 2014 Use _ArrayUnique on the array holding the returned list with duplicates - that way you only get each array listed once. So passing data to a function overrides what is defined in the function name? I thought it allowable to post this question in this thread because of my previous post.. But feel free to move it, or both.. I mean, I will have no intention of querying why.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
doestergaard Posted May 27, 2014 Author Share Posted May 27, 2014 Okay, using _arrayunique didn't Work, the with the code used from first post is: expandcollapse popup41 C:\drivers\CardReader\jmcr_jm.inf C:\drivers\Intel Grafik SP52568\2342hp64.inf C:\drivers\Intel IIPS SP52568\Impcd.inf C:\drivers\VFS_451 SP52162\vfs451.inf C:\drivers\VFS_471 SP52162\vfs471.inf C:\drivers\Image\HP HD Webcam [Fixed]\snp2uvc.inf C:\drivers\MEDIA\AMD High Definition Audio Device\AtihdLH3.inf C:\drivers\MEDIA\Intel(R) Display Audio\IntcDAud.inf C:\drivers\Modem\LSI HDA Modem\lsimdv64.inf C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\b57nd60a.inf C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\k57nd60a.inf C:\drivers\Net\HP Ethernet 10Gb 2-port 560FLB Adapter\ixn62x64.inf C:\drivers\Net\HP NC365T PCIe Quad Port Gigabit Server Adapter\E1R62x64.INF C:\drivers\Net\Intel(R) 82567LM-2 Gigabit Network Connection\E1Y62x64.INF C:\drivers\Net\Intel(R) 82575EB Multi-Function Network Device\E1Q62x64.INF C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1c62x64.inf C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1d62x64.inf C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1k62x64.inf C:\drivers\Net\Intel(R) Advanced Network Services Virtual Adapter\ansmw60e.inf C:\drivers\Net\Intel(R) Centrino(R) Wireless-N 100\NETwNs64.INF C:\drivers\Net\Intel(R) Ethernet Connection I217-LM\E1D62x64.INF C:\drivers\Net\Realtek PCIe FE Family Controller\netrtx64.inf C:\drivers\Net\VMware Accelerated AMD PCNet Adapter\vmware-nic.inf C:\drivers\NetTrans\Intel(R) Advanced Network Services Protocol\anspw60e.inf C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrl.inf C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrle.inf C:\drivers\System\HP Mobile Data Protection Sensor\accelerometer.inf C:\drivers\System\Intel(R) Management Engine Interface\HECI.inf C:\drivers\System\Intel(R) Management Engine Interface_1\HECI.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gbu11x.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gmdm2.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsdm2.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsen.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36wscard.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\WwanUsbMp.inf C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\wwanuss.inf C:\drivers\USB3\x64\nusb3hub.inf C:\drivers\USB3\x64\nusb3xhc.inf C:\drivers\USB3\x86\nusb3hub.inf C:\drivers\USB3\x86\nusb3xhc.inf C:\drivers\Mouse\Synaptics PS\2 Port Compatible TouchPad\synpd.inf also it writes the number of files found at the top, which i don't need. the hårdest part is understanding what the code from my first post does in the first place. Those stringregexreplace is a pain in the butt Thank you for you help! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 27, 2014 Moderators Share Posted May 27, 2014 (edited) somdcomputerguy,I do not understand your question. What I am suggesting is using something like _FileListToArrayRec to get a return of all the files matching the required mask, then looping through that array to remove the file names so all that is left are the folders in which the files were situated. That array is then passed through _ArrayUnique to remove duplicates. Of course, you could look inside the search function and add folder names to an array after searching to confirm if the name was not already present - but that would mean modifying the search function, which is usually a pretty complex beast. So I would do it as above - but I am not insistent. doestergaard,Just seen your last post - you did not remove the filenames, so of course _ArrayUnique did not work. Does the above explanation make it clearer: M23 Edited May 27, 2014 by Melba23 Typo Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
doestergaard Posted May 27, 2014 Author Share Posted May 27, 2014 Thank you Melba23 I think i got it, I will try your solution and see what I can come up with. I'll get back with the results Link to comment Share on other sites More sharing options...
mikell Posted May 27, 2014 Share Posted May 27, 2014 ? #include <Array.au3> #include <File.au3> $folderarray = _FileListToArrayRec("C:\Windows\", "*.inf", 1, 1, 0, 2) _ArrayDisplay($folderarray) Dim $paths[$folderarray[0]] For $i = 1 to $folderarray[0] $paths[$i-1] = StringRegExpReplace($folderarray[$i], '(.+)\\[^\\]+', "$1") Next _ArrayDisplay($paths) $res = _ArrayUnique($paths) _ArrayDisplay($res) doestergaard 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 27, 2014 Moderators Share Posted May 27, 2014 (edited) doestergaard,Here is my take using the files you listed: expandcollapse popup#include <Array.au3> #include <StringConstants.au3> $sLines = "41" & @CRLF & _ "C:\drivers\CardReader\jmcr_jm.inf" & @CRLF & _ "C:\drivers\Intel Grafik SP52568\2342hp64.inf" & @CRLF & _ "C:\drivers\Intel IIPS SP52568\Impcd.inf" & @CRLF & _ "C:\drivers\VFS_451 SP52162\vfs451.inf" & @CRLF & _ "C:\drivers\VFS_471 SP52162\vfs471.inf" & @CRLF & _ "C:\drivers\Image\HP HD Webcam [Fixed]\snp2uvc.inf" & @CRLF & _ "C:\drivers\MEDIA\AMD High Definition Audio Device\AtihdLH3.inf" & @CRLF & _ "C:\drivers\MEDIA\Intel(R) Display Audio\IntcDAud.inf" & @CRLF & _ "C:\drivers\Modem\LSI HDA Modem\lsimdv64.inf" & @CRLF & _ "C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\b57nd60a.inf" & @CRLF & _ "C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\k57nd60a.inf" & @CRLF & _ "C:\drivers\Net\HP Ethernet 10Gb 2-port 560FLB Adapter\ixn62x64.inf" & @CRLF & _ "C:\drivers\Net\HP NC365T PCIe Quad Port Gigabit Server Adapter\E1R62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82567LM-2 Gigabit Network Connection\E1Y62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82575EB Multi-Function Network Device\E1Q62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1c62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1d62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1k62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) Advanced Network Services Virtual Adapter\ansmw60e.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) Centrino(R) Wireless-N 100\NETwNs64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) Ethernet Connection I217-LM\E1D62x64.INF" & @CRLF & _ "C:\drivers\Net\Realtek PCIe FE Family Controller\netrtx64.inf" & @CRLF & _ "C:\drivers\Net\VMware Accelerated AMD PCNet Adapter\vmware-nic.inf" & @CRLF & _ "C:\drivers\NetTrans\Intel(R) Advanced Network Services Protocol\anspw60e.inf" & @CRLF & _ "C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrl.inf" & @CRLF & _ "C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrle.inf" & @CRLF & _ "C:\drivers\System\HP Mobile Data Protection Sensor\accelerometer.inf" & @CRLF & _ "C:\drivers\System\Intel(R) Management Engine Interface\HECI.inf" & @CRLF & _ "C:\drivers\System\Intel(R) Management Engine Interface_1\HECI.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gbu11x.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gmdm2.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsdm2.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsen.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36wscard.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\WwanUsbMp.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\wwanuss.inf" & @CRLF & _ "C:\drivers\USB3\x64\nusb3hub.inf" & @CRLF & _ "C:\drivers\USB3\x64\nusb3xhc.inf" & @CRLF & _ "C:\drivers\USB3\x86\nusb3hub.inf" & @CRLF & _ "C:\drivers\USB3\x86\nusb3xhc.inf" & @CRLF & _ "C:\drivers\Mouse\Synaptics PS\2 Port Compatible TouchPad\synpd.inf" $aLines = StringSplit($sLines, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT) _ArrayDisplay($aLines, "Full path", Default, 8) For $i = 1 To $aLines[0] $aLines[$i] = StringRegExpReplace($aLines[$i], "(^.*\\)(.*)", "\1") Next _ArrayDisplay($aLines, "Folder path", Default, 8) $aUnique = _ArrayUnique($aLines, 0, 1) _ArrayDisplay($aUnique, "Unique folders", Default, 8)M23Edit: I see mikell had the same idea. Edited May 27, 2014 by Melba23 doestergaard 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jguinch Posted May 27, 2014 Share Posted May 27, 2014 (edited) Same idea too, but without _ArrayUnique (processing the unique sort in the loop with Assign and IsDeclared). Should be faster expandcollapse popup#include <Array.au3> #include <StringConstants.au3> $sLines = "41" & @CRLF & _ "C:\drivers\CardReader\jmcr_jm.inf" & @CRLF & _ "C:\drivers\Intel Grafik SP52568\2342hp64.inf" & @CRLF & _ "C:\drivers\Intel IIPS SP52568\Impcd.inf" & @CRLF & _ "C:\drivers\VFS_451 SP52162\vfs451.inf" & @CRLF & _ "C:\drivers\VFS_471 SP52162\vfs471.inf" & @CRLF & _ "C:\drivers\Image\HP HD Webcam [Fixed]\snp2uvc.inf" & @CRLF & _ "C:\drivers\MEDIA\AMD High Definition Audio Device\AtihdLH3.inf" & @CRLF & _ "C:\drivers\MEDIA\Intel(R) Display Audio\IntcDAud.inf" & @CRLF & _ "C:\drivers\Modem\LSI HDA Modem\lsimdv64.inf" & @CRLF & _ "C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\b57nd60a.inf" & @CRLF & _ "C:\drivers\Net\3Com Dual Port 1000-SX PCI-X Server NIC\k57nd60a.inf" & @CRLF & _ "C:\drivers\Net\HP Ethernet 10Gb 2-port 560FLB Adapter\ixn62x64.inf" & @CRLF & _ "C:\drivers\Net\HP NC365T PCIe Quad Port Gigabit Server Adapter\E1R62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82567LM-2 Gigabit Network Connection\E1Y62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82575EB Multi-Function Network Device\E1Q62x64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1c62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1d62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) 82579LM Gigabit Network Connection\e1k62x64.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) Advanced Network Services Virtual Adapter\ansmw60e.inf" & @CRLF & _ "C:\drivers\Net\Intel(R) Centrino(R) Wireless-N 100\NETwNs64.INF" & @CRLF & _ "C:\drivers\Net\Intel(R) Ethernet Connection I217-LM\E1D62x64.INF" & @CRLF & _ "C:\drivers\Net\Realtek PCIe FE Family Controller\netrtx64.inf" & @CRLF & _ "C:\drivers\Net\VMware Accelerated AMD PCNet Adapter\vmware-nic.inf" & @CRLF & _ "C:\drivers\NetTrans\Intel(R) Advanced Network Services Protocol\anspw60e.inf" & @CRLF & _ "C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrl.inf" & @CRLF & _ "C:\drivers\Ports\Intel(R) Active Management Technology - SOL\mesrle.inf" & @CRLF & _ "C:\drivers\System\HP Mobile Data Protection Sensor\accelerometer.inf" & @CRLF & _ "C:\drivers\System\Intel(R) Management Engine Interface\HECI.inf" & @CRLF & _ "C:\drivers\System\Intel(R) Management Engine Interface_1\HECI.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gbu11x.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gmdm2.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsdm2.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36gsen.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\h36wscard.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\WwanUsbMp.inf" & @CRLF & _ "C:\drivers\USB\HP hs2320 Mobile Broadband Module USB Device\wwanuss.inf" & @CRLF & _ "C:\drivers\USB3\x64\nusb3hub.inf" & @CRLF & _ "C:\drivers\USB3\x64\nusb3xhc.inf" & @CRLF & _ "C:\drivers\USB3\x86\nusb3hub.inf" & @CRLF & _ "C:\drivers\USB3\x86\nusb3xhc.inf" & @CRLF & _ "C:\drivers\Mouse\Synaptics PS\2 Port Compatible TouchPad\synpd.inf" $aLines = StringSplit($sLines, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT) _ArrayDisplay($aLines, "Full path", Default, 8) $n = 1 For $i = 1 To $aLines[0] $sDir = StringRegExpReplace($aLines[$i], "\\[^\\]+$", "") If NOT IsDeclared( "DIR_" & StringToBinary($sDir) ) Then Assign("DIR_" & StringToBinary($sDir), 1) $aLines[$n] = $sDir $n += 1 EndIf Next Redim $aLines[$n] $aLines[0] = UBound($aLines) - 1 _ArrayDisplay($aLines) Edited May 27, 2014 by jguinch doestergaard 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
doestergaard Posted May 27, 2014 Author Share Posted May 27, 2014 omg! thank you Guys! This was exactly what I was looking for! I Owe you my gratitude Link to comment Share on other sites More sharing options...
DXRW4E Posted May 28, 2014 Share Posted May 28, 2014 (edited) official way will have to be this expandcollapse popup#include <Array.au3> If Not IsDeclared("arDllCall") Then Global Static $arDllCall EndIf Global Const $hSetupApiDll = DllOpen("SetupApi.dll") Global Const $hKernel32DLL = DllOpen("Kernel32.dll") Global Const $ERROR_INSUFFICIENT_BUFFER = 122 ;(0x7A) - The data area passed to a system call is too small. Local $aInfFieList =_FileListToArrayEx(@WindowsDir & "\inf", "*.Inf", 13) _ArrayDisplay($aInfFieList) MsgBox(0, 1, _SetupGetInfFileList(Null)) Local $sInfFieList, $aDirectoryPath = _FileListToArrayEx(@WindowsDir & "\inf", "*", 14) If Not @Error Then For $i = 1 To $aDirectoryPath[0] $sInfFieList &= _SetupGetInfFileList($aDirectoryPath[$i]) Next EndIf MsgBox(0, 1, $sInfFieList) ; #FUNCTION# ======================================================================================================================================================= ; Name...........: _FileListToArrayEx ; Description ...: Lists files and\or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax.........: _FileListToArrayEx($sPath[, $sFilter = "*"[, $iFlag = 0]]) ; Parameters ....: $sPath - Path to generate filelist for. ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.png|*.jpg|*.bmp") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iFlag - Optional: specifies whether to return files folders or both Or Full Path (add the flags together for multiple operations): ; |$iFlag = 0 (Default) Return both files and folders ; |$iFlag = 1 Return files only ; |$iFlag = 2 Return Folders only ; |$iFlag = 4 Search SubDirectory ; |$iFlag = 8 Return Full Path ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of file found, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp (Can not be combined with flag 16) ; |$iFlag = 128 Return Backslash at the beginning of the file name, example Return "\Filename1.xxx" (Can not be combined with flag 8) ; Return values .: Failure - @Error ; |1 = Path not found or invalid ; |2 = Invalid $sFilter ; |3 = No File(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Files\Folders returned ; $array[1] = 1st File\Folder ; $array[2] = 2nd File\Folder ; $array[3] = 3rd File\Folder ; $array[n] = nth File\Folder ; Related .......: ; Link ..........: ; Example .......: Yes ; Note ..........: Special Thanks to SolidSnake & Tlem ; ================================================================================================================================================================== Func _FileListToArrayEx($sPath, $sFilter = "*", $iFlag = 0) Local Const $hSR = StringRegExpReplace $sPath = $hSR($sPath & "\", "(?!\A)[\\/]+\h*", "\\") If Not FileExists($sPath) Then Return SetError(1, 1, "") If StringRegExp($sFilter, (BitAND($iFlag, 64) ? '^\s*$|\v|[\\/:><"]|^\||\|\||\|$' : '^\s*$|\v|\\')) Then Return SetError(2, 2, "") Local $hSearch, $sFile, $sFileList, $sSubDir = BitAND($iFlag, 4), $sDelim = (BitAND($iFlag, 128) ? "|\" : (BitAND($iFlag, 8) ? "|" & $sPath : "|")) $hSearch = FileFindFirstFile($sPath & "*") If @Error Then Return SetError(3, 3, "") Local $hWSearch = $hSearch, $hWSTMP, $SearchWD, $iExtended, $iFlags = (BitAND($iFlag, 3) = 3 ? 0 : BitAND($iFlag, 3)), $iFilter = $sFilter = "*" ? 0 : 1 If Not BitAND($iFlag, 64) Then $sFilter = (BitAND($iFlag, 16) ? "(" : "(?i)(") & $hSR($hSR($hSR($hSR($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While 1 $sFile = FileFindNextFile($hWSearch) If @Error Then If $hWSearch = $hSearch Then ExitLoop FileClose($hWSearch) $hWSearch -= 1 $SearchWD = StringLeft($SearchWD, StringInStr($SearchWD, "\", 1, -2)) ElseIf $sSubDir Then $iExtended = @Extended If ($iFlags + $iExtended <> 2) Then If $iFilter Then If StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $SearchWD & $sFile Else $sFileList &= $sDelim & $SearchWD & $sFile EndIf EndIf If Not $iExtended Then ContinueLoop $hWSTMP = FileFindFirstFile($sPath & $SearchWD & $sFile & "\*") If $hWSTMP = -1 Then ContinueLoop $hWSearch = $hWSTMP $SearchWD &= $sFile & "\" ElseIf ($iFlags + @Extended) <> 2 And StringRegExp($sFile, $sFilter) Then $sFileList &= $sDelim & $sFile EndIf WEnd FileClose($hSearch) If Not $sFileList Then Return SetError(3, 3, "") Return StringSplit(StringTrimLeft($sFileList, 1), "|", StringReplace(BitAND($iFlag, 32), "32", 2)) EndFunc ;==>_FileListToArrayEx ; #FUNCTION# ============================================================================================================================================== ; Name...........: _SetupGetInfFileList ; Description ...: The SetupGetInfFileList function returns a list of INF files located in a caller-specified directory to a call-supplied buffer. ; Syntax.........: _SetupGetInfFileList($DirectoryPath, $InfStyle) ; Parameters ....: $DirectoryPath - Optional pointer to a null-terminated string containing the path of the directory in which to search. ; If this value is NULL, the %windir%\inf directory is used. ; $InfStyle - Type of INF file to search for. May be a combination of the following flags. ; |$INF_STYLE_OLDNT (1) - A legacy INF file format. ; |$INF_STYLE_WIN4 (2) - A Windows INF file format. ; Return values .: If the function succeeds, the return value is a String Inf file List value. ; Remarks .......: ; Related .......: ; Author ........: DXRW4E ; ========================================================================================================================================================= Func _SetupGetInfFileList($sDirectoryPath, $InfStyle = 2) $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "WSTR", "", "DWORD", Null, "DWORD*", 0) If @Error Then Return SetError(@Error, 0, 0) ;If Not $arDllCall[0] And _WinAPI_GetLastErrorEx() = $ERROR_INSUFFICIENT_BUFFER Then $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "WSTR", "", "DWORD", $arDllCall[5], "DWORD*", 0) ;If $arDllCall[0] Then Return SetError(0, $arDllCall[5], $arDllCall[3]) Local $ReturnBuffer = DllStructCreate("BYTE[" & $arDllCall[5] * 2 & "]") $arDllCall = DllCall($hSetupApiDll, "BOOL", "SetupGetInfFileListW", "WSTR", $sDirectoryPath, "DWORD", $InfStyle, "STRUCT*", $ReturnBuffer, "DWORD", $arDllCall[5], "DWORD*", 0) If $arDllCall[0] Then Return SetError(0, $arDllCall[5], StringRegExpReplace(BinaryToString(DllStructGetData($ReturnBuffer, 1), 2), "\x00+", @LF)) Return SetError(_WinAPI_GetLastErrorEx(), 0, -1) EndFunc ;==>_SetupGetInfFileList Func _WinAPI_GetLastErrorEx() $arDllCall = DllCall($hKernel32DLL, "long", "GetLastError") Return $arDllCall[0] EndFunc ;==>_WinAPI_GetLastErrorEx Ciao. Edited May 28, 2014 by DXRW4E doestergaard 1 Link to comment Share on other sites More sharing options...
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