Looking for file in two-wildcard path Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Looking for file in two-wildcard path

21 Aug 2017, 02:41

Hello.

I got this piece of script that can dig into two-wildcard path and retrieve filename.
But it cannot do the "else" action (if file doesn't exist).

What am I doing wrong here?

Code: Select all

Loop, Files, %sourcepdf1% , D
{
sourcepdf2 = % A_LoopFileLongPath . bslash . elemname . pdfstar
Loop, Files, %sourcepdf2%
{
If FileExist(A_LoopFileLongPath)
{
Gosub, Fileexistroutine
}
else
{
Gosub, Filenotexistroutine
}
}  ;;; end of if fileexist
}  ;;; end of loop2
}  ;;; end of loop1
I know that I couldn't have Filepattern with two wildcards - p:\laser\bkf\bend\14*\2-14-2*.pdf so i split it based on some example found in old forum.

Problem is :
Fileexistroutine is launched properly, but "else" is skipped.
I've tried to use If !FileExist(A_LoopFileLongPath) - no result.

Also was trying to use IfExist but this cannot work with "else"
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Looking for file in two-wildcard path

21 Aug 2017, 09:07

what you posted has an extra curly brace "}"
User avatar
BriHecato
Posts: 124
Joined: 18 Jul 2017, 07:17

Re: Looking for file in two-wildcard path  Topic is solved

27 Aug 2017, 12:14

I found my solution inbetween.
Needed to add If FileExist for sourcepdf2 like in this piece of code

Code: Select all

Loop, Files, %sourcepdf1% , D
	{
		sourcepdf2 = % A_LoopFileLongPath . bslasz . elemname . pdfstar
		If FileExist(sourcepdf2)
		{
			Loop, Files, %sourcepdf2%			
			{
				If FileExist(A_LoopFileLongPath)
				{..... etc
And all start to working
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Looking for file in two-wildcard path

27 Aug 2017, 13:28

Try this.

Code: Select all

files := WildcardSearch("p:\laser\bkf\bend\14*", "\2-14-2*.pdf")
for i, v in files {
	res .= v "`n"
}
MsgBox, % res

WildcardSearch(paths*) {
	Folders := [paths[1]]
	for i, path in paths {
		TmpFolders := []
		for j, folder in Folders {
			Loop, Files, % folder (i != 1 ? path : ""), % (i != paths.Length() ? "D" : "F")
			{
				TmpFolders.Push(A_LoopFileFullPath)
			}
		}
		Folders := TmpFolders
	}
	return Folders
}
Please excuse my spelling I am dyslexic.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Theda and 279 guests