| View previous topic :: View next topic |
| Author |
Message |
John B.
Joined: 21 Oct 2006 Posts: 21
|
Posted: Tue Dec 11, 2007 4:19 pm Post subject: Limiting files matched in a file loop |
|
|
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 |
|
 |
Mustang
Joined: 17 May 2007 Posts: 421 Location: England
|
Posted: Tue Dec 11, 2007 6:41 pm Post subject: Re: Limiting files matched in a file loop |
|
|
| 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 |
|
 |
John B.
Joined: 21 Oct 2006 Posts: 21
|
Posted: Tue Dec 11, 2007 6:54 pm Post subject: |
|
|
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 |
|
 |
Mustang
Joined: 17 May 2007 Posts: 421 Location: England
|
Posted: Tue Dec 11, 2007 11:51 pm Post subject: |
|
|
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 |
|
 |
John B.
Joined: 21 Oct 2006 Posts: 21
|
Posted: Wed Dec 12, 2007 12:32 am Post subject: |
|
|
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 |
|
 |
|