AutoHotkey Community

It is currently May 26th, 2012, 12:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: December 11th, 2007, 5:19 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 11th, 2007, 7:41 pm 
Offline

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 7:54 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
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.


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

Joined: May 17th, 2007, 9:06 pm
Posts: 421
Location: England
Ah seams like a bug to me
Try this as a workaround:
Code:
Loop, *.hhc, , 0
{
    IfNotInString, A_LoopFileFullPath, .hhc_
    {
        MsgBox, %A_LoopFileFullPath%
    }
}


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

Joined: October 21st, 2006, 7:00 pm
Posts: 21
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.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], rbrtryn, Yahoo [Bot] and 12 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