AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Limiting files matched in a file loop

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
John B.



Joined: 21 Oct 2006
Posts: 21

PostPosted: Tue Dec 11, 2007 4:19 pm    Post subject: Limiting files matched in a file loop Reply with quote

Hi,

I'm performing some operations on a file in a directory. I know the file extension of the file (*.hhc), but not the full file name. The only way I could think of to get the file name is to use a file loop:
Code:

Loop, *.hhc, , 0
{
  ; process the *.hhc file
}


The problem with doing this is that the loop also gets unwanted files like *.hhc.backup and *.hhc.old

1. Is there a way to limit the files in a file loop so that it only gets the files that match exactly the file pattern (instead of matching the file pattern somewhere is the file name)?

2. Is there a better way to get the file name when I only know the file extension?

Thanks,
John B.
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 421
Location: England

PostPosted: Tue Dec 11, 2007 6:41 pm    Post subject: Re: Limiting files matched in a file loop Reply with quote

John B. wrote:
with doing this is that the loop also gets unwanted files like *.hhc.backup and *.hhc.old

For me it does not do this
I only get %A_LoopFileName% for *.hhc files
Back to top
View user's profile Send private message
John B.



Joined: 21 Oct 2006
Posts: 21

PostPosted: Tue Dec 11, 2007 6:54 pm    Post subject: Reply with quote

Hi,

I mis-stated one thing about the file names. Try this:

Create two files in a directory:
a.hhc
a.hhc_backup

In the same directory, create this AHK script:
Code:

Loop, *.hhc, , 0
{
  msgbox, %A_LoopFileFullPath%
}
Return


Run the script. When I run it, I get two message boxes, one for a.hhc and one for a.hhc_backup.

Thanks,
John B.
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 421
Location: England

PostPosted: Tue Dec 11, 2007 11:51 pm    Post subject: Reply with quote

Ah seams like a bug to me
Try this as a workaround:
Code:
Loop, *.hhc, , 0
{
    IfNotInString, A_LoopFileFullPath, .hhc_
    {
        MsgBox, %A_LoopFileFullPath%
    }
}
Back to top
View user's profile Send private message
John B.



Joined: 21 Oct 2006
Posts: 21

PostPosted: Wed Dec 12, 2007 12:32 am    Post subject: Reply with quote

Hi Mustang,

Interesting validation. I'll bet I could use RegExMatch to be more exclusive, since I'd want to exclude all file extensions that don't exactly match .hhc.
This appears to work:
Code:
Loop, *.hhc, , 0
{
  If RegExMatch(A_LoopFileFullPath, "\.hhc$")
    msgbox, %A_LoopFileFullPath%
}


Thanks for the idea of validating the file name. I thnk it will solve the problem.

John B.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group