AutoHotkey Community

It is currently May 26th, 2012, 1:09 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: December 12th, 2007, 1:39 am 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi,

I posted a question over in Ask for Help, but it's led me to make a suggestion as well. The problem I encountered is that the Filepattern in a file loop can match a string anywhere in the file name. Thus:
Code:
Loop, *.hhc

matches a.hhc AND a.hhc_backup

But if the Filepattern could be a regular expression, then I could specify the pattern as
Code:
Loop, *\.hhc$

to specifically match just the file extension I want.

Thanks,
John B.
(who just loves regular expressoins)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2007, 12:13 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
This would break existing scripts and also slow down if regex is not needed.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 5:47 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
perhaps we could add then SetLoopMatchMode as in SetTitleMatchMode, which has a regex option.

This would make a powerful grep-like tool.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 6:05 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I like engineers idea, an regexmatch equality operator would be fantastic! Something similar to perl, e.g. if ("abcdef" ~= "\w{1,10}") == true

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 8:22 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
A regex match operator??? Wow, sounds very good idea to me, I would find it also very useful.
If (var ~= var2)
I like that syntax.

Back again to topic, the SetLoopMatchMode option seems to be a simple solution to me. But, is this really needfull? First, we should answer this question.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 8:25 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
It would be extremely powerful

The equivalent would be to
Code:
Loop, *.*
{
  if not regexmatch(A_LoopFileFullPath, "REGEX")
    continue
  ;rest of loop here
}

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 8:16 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
We often need regex. Instead to create new operator or special coded support of regex at some functions, I wish we could specifiy every (expression-) string or variable as a regex. That is more natural and usable in more situations. In example with a special symbol or character (example the ~ symbol) AutoHotkey knows the next string is a regex. This allows us in general to write faster regex. Of course we cannot use in that case all features, i.e. the parameters. But it could lead also to faster code, because there is less to parse. And ErrorLevel could be automatically set to last match.

Code:
If (var = ~"??\.??")
    MsgBox %ErrorLevel%

Loop, ~%var%
    MsgBox %A_LoopFileFullPath%


Last edited by Tuncay on August 23rd, 2009, 7:40 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 7:34 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
++

RegEx everywhere FTW.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 8:21 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
As far as I understand this is not possible because it is not supported by FindFirstFile Function :(

MSDN FindFirstFile Function wrote:
...
Parameters

lpFileName [in]
    The directory or path, and the file name, which can include wildcard characters, for example, an asterisk (*) or a question mark (?).
...

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 9:24 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
^ That's hardly an obstacle; as Engunneer pointed out, a "Loop, FilePatternRegex" could check each filepath against the needle. Such a loop might instead create a list of files, filter them with the needle, and loop through the filtered list.

As far as syntax goes, I think something along the lines of Loop, FileRegex, NeedleRegex, [include folders, recurse] would make more sense than a SetLoopMatchMode, ... and it would be consistent with the syntax for other special loops.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2009, 10:08 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
[VxE] wrote:
^ That's hardly an obstacle; as Engunneer pointed out, a "Loop, FilePatternRegex" could check each filepath against the needle. Such a loop might instead create a list of files, filter them with the needle, and loop through the filtered list.


This would be similar to this and would be not much faster as I understand:
Code:
Loop, C:\*,1,1
 If RegExMatch(A_LoopFileLongPath,"^.*\.ahk$")
  MsgBox % A_LoopFileName

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2009, 3:13 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
Heh, if there were no way to specify a 'starting folder' for the loop, then, yes, that would be an accurate illustration.

Anyways, I'm not convinced that there is an elegant, intuitive solution for combining a file loop with regex, however, what good is it to say it's impossible ?

For the time being, using something like
Code:
Loop, %A_MyMusic%\* ; a normal file loop has limited precision regarding wildcards
{
  if not regexmatch(A_LoopFileName, "REGEX") ; A_LoopFileName could instead be any file-loop variable
    continue
  ;rest of loop here
}
is more than sufficient, and it's unlikely to confuse anyone. The OP is merely arguing that he/she would like it to be condensed into its own type of loop.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group