limit loop files & folders to an exact match?

Get help with using AutoHotkey and its commands and hotkeys
nathansu
Posts: 8
Joined: 23 Aug 2016, 09:17

limit loop files & folders to an exact match?

06 Oct 2016, 13:30

I'm using the snippet below to take user input (via GUI) and find a matching folder.

So, the user enters a customer ID like "A123" and this loop finds the full path. These folders are usually named something like "A123 Acme Industries" but when the user is doing the entry, it's much easier to enter only those first 4 characters.

Code: Select all

Loop, Q:\QA ORDERS\%CustID%*.*,2
	{
		JobDirCheck := A_LoopFileLongPath . "\" . JobNum ; set variable for job directory 
	}
The problem is that if someone enters an incorrect ID (A132 instead of A123), the Loop function will return the closest match. Well, it will return *a* match. I'm not sure how it determines. What I'd like to implement is some kind of interrupt that if an exact match isn't found.

That is, an exact match for those first 4 characters.

If an exact match isn't found, I'd like to stop the script so that the user can double-check the ID and try again.

Thanks!
ahkForWork
Posts: 92
Joined: 28 Mar 2016, 07:59

Re: limit loop files & folders to an exact match?

06 Oct 2016, 13:45

if JobNum is 'A123' it will show the message box that the file was found if its found in the file name on the loop iteration. otherwise it will tell the user to check and try again.
also added in the splitpath command and its parameters for you in case its needed.

Code: Select all

; To fetch all info:
;~ SplitPath, A_LoopFileLongPath, name, dir, ext, name_no_ext, drive
; The above will set the variables as follows:
; name = Address List.txt
; dir = C:\My Documents
; ext = txt
; name_no_ext = Address List
; drive = C:

Loop, Q:\QA ORDERS\%CustID%*.*,2
{
	;~ JobDirCheck := A_LoopFileLongPath . "\" . JobNum
	if (isntr(A_LoopFileLongPath,JobNum)) {
		MsgBox % "File Found"
		fileFound := true
		break
	}
}

if (!fileFound) {
	MsgBox % "file not found, please try again."
}
return
drawback
Posts: 34
Joined: 11 Aug 2016, 11:31

Re: limit loop files & folders to an exact match?

06 Oct 2016, 13:49

If CustID is "A132" and no directory in "Q:\QA ORDERS\" exists that begins with "A132" than JobDirCheck isn't set at all so there is no *a* match...

Code: Select all

Q:\QA ORDERS\%CustID%*.*
You are processing folders, not files, why are you using "*.*"?
"*" is sufficient

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, nutnutwin and 28 guests