Anteaus Posted April 19, 2010 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.
Spiff59 Posted April 19, 2010 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")
KaFu Posted April 19, 2010 Posted April 19, 2010 Ascend4nt has written an UDF for that. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
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