Zomp Posted August 18, 2008 Share Posted August 18, 2008 (edited) Which is the simple way I can check if a file matches a specified mask? That is, I'm looking a function that works as follows: Match("zomp.au3","*.*") -> True Match("zomp.au3","zo*.*") -> True Match("zomp.au3","zo*.txt") -> False I recognize that I can write a UDF function using StringRegExp, but I wonder if there is something easier. Thanks. Edited August 18, 2008 by Zomp Link to comment Share on other sites More sharing options...
JRowe Posted August 19, 2008 Share Posted August 19, 2008 StringInStr might help you http://www.autoitscript.com/autoit3/docs/f...StringInStr.htm [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] Link to comment Share on other sites More sharing options...
Zomp Posted August 19, 2008 Author Share Posted August 19, 2008 StringInStr might help you http://www.autoitscript.com/autoit3/docs/f...StringInStr.htmIf I remember well, StringInstr does not allow to use wildcards as ? and *. Link to comment Share on other sites More sharing options...
Anteaus Posted August 19, 2008 Share Posted August 19, 2008 The key point here is that the AutoIt regexp uses unix logic, which is not the same as DOS logic. I too got caught out by this because I didn't read the instructions. * in unix regexps has a very different meaning from * in dos. Link to comment Share on other sites More sharing options...
Zomp Posted August 19, 2008 Author Share Posted August 19, 2008 The key point here is that the AutoIt regexp uses unix logic, which is not the same as DOS logic. I too got caught out by this because I didn't read the instructions. * in unix regexps has a very different meaning from * in dos.Yes I know. To have a function like the one I have described one can use StringInstr or StringRegExp to "translate" wildcards ? and *. Which is the easier way to do? Is there any other alternative? This is my questions. Link to comment Share on other sites More sharing options...
therks Posted August 19, 2008 Share Posted August 19, 2008 Is there any other alternative?I don't think so. I wrote a function that does this a while ago. Func _FileMatch($sFile, $sFilter) Local $sChar, $sChars = '\.+[^]$(){}=!<>|:' For $i = 1 to StringLen($sChars) $sChar = StringMid($sChars, $i, 1) $sFilter = StringReplace($sFilter, $sChar, '\' & $sChar) Next $sFilter = StringReplace($sFilter, '?', '.{1}') $sFilter = StringReplace($sFilter, '*', '.*') Return StringRegExp($sFile, $sFilter) EndFunc ; Examples consolewrite(_FileMatch('file.txt', '*.txt') & @CRLF) consolewrite(_FileMatch('file.txt', 'file.*') & @CRLF) consolewrite(_FileMatch('file.txt', 'file.t??') & @CRLF) consolewrite(_FileMatch('file.txt', 'file.t?x') & @CRLF) ; This is the only one I'm having a problem with that I've tested. ; ComSpec will match this, but I'm not sure the best way to get this ; function to match it. consolewrite(_FileMatch('file.txt', 'file.txt?') & @CRLF) consolewrite(@CRLF) ; Here's your examples: consolewrite(_FileMatch("zomp.au3","*.*") & @CRLF) consolewrite(_FileMatch("zomp.au3","zo*.*") & @CRLF) consolewrite(_FileMatch("zomp.au3","zo*.txt") & @CRLF) My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Zomp Posted August 19, 2008 Author Share Posted August 19, 2008 I don't think so. I wrote a function that does this a while ago. Func _FileMatch($sFile, $sFilter) Local $sChar, $sChars = '\.+[^]$(){}=!<>|:' For $i = 1 to StringLen($sChars) $sChar = StringMid($sChars, $i, 1) $sFilter = StringReplace($sFilter, $sChar, '\' & $sChar) Next $sFilter = StringReplace($sFilter, '?', '.{1}') $sFilter = StringReplace($sFilter, '*', '.*') Return StringRegExp($sFile, $sFilter) EndFunc Good work, thanks. 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