Anteaus 0 Posted April 19, 2010 I need to filter a list of files on the basis of a wildcarded DOS search criterion, for example "p*.mp?". This will take the form of a function which accepts a filename and a wildcard-mask as inputs, and returns either true (filename is within scope of mask) or false if it is not. Just wondered if anyone has a readymade regex to do this kind of thing, if so it would save me some head-scratching. Share this post Link to post Share on other sites
Spiff59 54 Posted April 19, 2010 This is something I recall a bunch of us playing with a while back in a discussion about creating a (pseudo) recursive _FileListToArray() function. I'm not sure this was entirely complete or debugged. Someone may have a better version around, but this may work for a starter... $sIncludeList = "??x.*" $File1 = "box.txt" $File2 = "xxxx.txt" ; Convert to Regular Expression, step 1: Wrap brackets around (protect) "." and "$" (other characters needed?) $sIncludeList = StringRegExpReplace($sIncludeList, '[.$]', '\[\0\]') ; Convert to Regular Expression, step 2: Convert '?' to '.', and '*' to '.*?' $sIncludeList = StringReplace(StringReplace($sIncludeList, "?", "."), "*", ".*?") ; Convert to Regular Expression, step 3; make case-insensitive, match from first char, terminate strings $sIncludeList = "(?i)\A(" & $sIncludeList & "$)" MsgBox(1,"",$sIncludeList) If StringRegExp($File1, $sIncludeList) Then MsgBox(1,"","File1 matches") If StringRegExp($File2, $sIncludeList) Then MsgBox(1,"","File2 matches") Share this post Link to post Share on other sites
KaFu 296 Posted April 19, 2010 Ascend4nt has written an UDF for that. OS: Win10-1909 - 64bit - German, AutoIt Version: 3.3.14.5, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2019-Dec-21) BIC - Batch-Image-Cropper (2019-Dec-11) COP - Color Picker (2009-May-21) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2019-Dec-07) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Share this post Link to post Share on other sites