kadanefewi Posted June 1, 2016 Share Posted June 1, 2016 (edited) Hey people. I'm iterating over a list of files from all drives and want to know if it matches on a certain extension. I'm getting a 0 (no match), where there clearly is a match. For $i = 1 To $aFiles[0] $exceptionIndex = StringInStr($aFiles[$i], ".txt") If $exceptionIndex > 0 Then ;do stuff EndIf Next This is happening on a drive which is a VirtualBox mounted CD (this case the VirtualBox tools). It's read only. I'm mentioning it because I had some strange behavior on VirtualBox mounted drives in the past (memory leaks when iterating over mounted VirtualBox shared folders). Has anyone seen any similar issues? Have the same problem if I use StringRegExp. Edited June 1, 2016 by kadanefewi Link to comment Share on other sites More sharing options...
water Posted June 1, 2016 Share Posted June 1, 2016 How do you populate the $aFiles array? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
spudw2k Posted June 1, 2016 Share Posted June 1, 2016 (edited) I'd suggest you use the _FileListToArray or _FileListToArrayRec functions to search for the text files first. This should give better performance by the fact that the array will only be populated with ".txt" files versus having non ".txt" files in the array and having to evaluate every file. #include <File.au3> _Demo() Func _Demo() $sSourcePath = @ScriptDir $aFiles = _FileListToArrayRec($sSourcePath, "*.txt",$FLTAR_FILES,$FLTAR_RECUR) If UBound($aFiles) <= 1 Then Return SetError(1, 0, 0) For $iX = 1 to $aFiles[0] ;Do something ConsoleWrite($aFiles[$iX] & @CRLF) Next EndFunc Edited June 1, 2016 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
kadanefewi Posted June 1, 2016 Author Share Posted June 1, 2016 (edited) 58 minutes ago, water said: How do you populate the $aFiles array? Hey man! You always reply to my posts, thank you. I was going to answer your question, but I started thinking about this... I have several conditions that might impact in whether the file is matched or not, not just this, it's another list. The problem was that I have a list of conditions that I took from a .txt file and converted to a binary string (if that's a thing). This ".txt" is one of them. I had several such lists, obtained from different strings. The problem was that some were formatted with Windows, other Linux EOL. I used @CR to populate the array from the string, because @CRLF failed with another array, so I didn't think much about it and just used it for all. So, basically I was telling autoit to match on ".txt" & @LF, that's why it wasn't finding the match. Thank you! Edited June 1, 2016 by kadanefewi Clarifications Link to comment Share on other sites More sharing options...
kadanefewi Posted June 1, 2016 Author Share Posted June 1, 2016 17 minutes ago, spudw2k said: I'd suggest you use the _FileListToArray or _FileListToArrayRec functions to search for the text files first. This should give better performance by the fact that the array will only be populated with ".txt" files versus having non ".txt" files in the array and having to evaluate every file. #include <File.au3> _Demo() Func _Demo() $sSourcePath = @ScriptDir $aFiles = _FileListToArrayRec($sSourcePath, "*.txt",$FLTAR_FILES,$FLTAR_RECUR) If UBound($aFiles) <= 1 Then Return SetError(1, 0, 0) For $iX = 1 to $aFiles[0] ;Do something ConsoleWrite($aFiles[$iX] & @CRLF) Next EndFunc Hey Spud, thanks. Yes, I'm doing that, but this is a blacklist match, meaning I need to remove several extensions from a _FileListToArrayRec, to I had to come up way to filter on several conditions. See my other reply for what was the problem. Link to comment Share on other sites More sharing options...
spudw2k Posted June 1, 2016 Share Posted June 1, 2016 ah got it. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
water Posted June 1, 2016 Share Posted June 1, 2016 Ah, another problem solved by asking the right questions, make the user think about it and letting him find the solution himself kadanefewi and spudw2k 2 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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