Program Not Running, wrong Syntax? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
eblanc
Posts: 68
Joined: 08 May 2019, 14:41

Program Not Running, wrong Syntax?

22 May 2019, 11:57

Hi, I'm developing a code that will create a new directory, and templates. On an already existing Large database. But I I need it to check if folder already exists, to cancel the program. And I would like it to open the folder if it does exist.

It's able to tell me if file exists or not. But when it tries to launch it won't open the folder. I think it has to do something with the syntax of the asterisk.

Code: Select all

;NEW TEST FOR TEMPLATE
!z::
inputbox, userinput, Create New Project Template, Please Enter Full Project ID of the new project you wish to create, ,300 ,140
	;If the user pressed cancel or the string is too short
	if (ErrorLevel || StrLen(userinput) < 15)
		{
		msgbox, , Project ID too Short, Please enter full project ID with the correct format.
		return
		}
ifexist % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	{
	msgbox, 16, Overwrite Protection Safety, This Folder Already exists, cannot overwrite files or folders. Opening File directory instead
	Run, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	}
else
msgbox, file does not exists
return
I had a script before that I got help with that found directory even if last characters didn't match 100%. This script works perfect, I've been using it as a reference and it has the same directory syntax, so not sure what is my first code having problem opening the folder.

Code: Select all

!a::
    inputbox, userinput, Enter Full Project ID, , ,300 ,100
    ; If the user pressed cancel or the string is too short
    if (ErrorLevel || StrLen(userinput) = 0) 
    		return
    FoundFile := ""
    Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
    {
		
        FoundFile := A_LoopFileFullPath
        break
    }
    if (FoundFile != "")
        Run, % FoundFile
	Else
	IfExist, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\"
	{
	MsgBox, 64,Folder Not Found, % "Folder Name was not found. Opening Territory Folder instead (" SubStr(userinput, 1, 4) ")"
	Run, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\"
	}
	else 
	{
		msgbox, 16,Folder Not Found, % "Territory Code (" SubStr(userinput, 1, 4) ") Does not Exist. Opening Webcam Projects Folder instead"
		Run, I:\My Drive\Webcam\Webcam - Projects\%no%\, , UseErrorLevel	 
	}
Return
Any help or ideas, much appreciated. Thank you!
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: Program Not Running, wrong Syntax?

22 May 2019, 13:34

eblanc wrote:
22 May 2019, 11:57

Code: Select all

	ifexist % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	[...]
	Run, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
What's that last , D supposed to do?

Personally, I'd do it like this:

Code: Select all

Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	{
	FilePath:=A_LoopFileLongPath
	Break
	}
IfExist, %FilePath% ; Or even "If InStr(FileExist(FilePath),"D")", but this is a bit redundant
	{
	; whatever else here
	Run, %FilePath%
	}
User avatar
eblanc
Posts: 68
Joined: 08 May 2019, 14:41

Re: Program Not Running, wrong Syntax?

24 May 2019, 12:43

Sam_ wrote:

Code: Select all

Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	{
	FilePath:=A_LoopFileLongPath
	Break
	}
IfExist, %FilePath% ; Or even "If InStr(FileExist(FilePath),"D")", but this is a bit redundant
	{
	; whatever else here
	Run, %FilePath%
	}
Hi Sam, Not sure what the , D at the end is remarking too. This script was made with the assistance of somebody else. So far it' works, which is why I haven't changed.

I tried your script. But it doesn't recognize different "ID" Numbers. Any idea how to solve it?

Code: Select all

;Making New Template
!z::
	inputbox, userinput, Create New Project Template, Please Enter Full Project ID of the new project you wish to create., ,300 ,150
	if ErrorLevel cancel
	Return
	FoundFile := ""
    Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" SubStr(userinput, 1, 4) "\" SubStr(userinput, 1, 15) "*", D
	{
	FilePath:=A_LoopFileLongPath
	Break
	}
IfExist, %FilePath% ; Or even "If InStr(FileExist(FilePath),"D")", but this is a bit redundant
	{
	msgbox, File already exist doofus!!!
	; whatever else here
	Run, %FilePath%
	return
	}
	Else
	{
	;Start Copying files, etc.
	msgbox, 4, Creating New Project Directory, You are Creating a new Project Directory, 
	clipboard = %userinput%
	No := SubStr(userinput, 1, 4)
	msgbox, filecreatedir, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
	sleep, 600
	msgbox, filecopy, I:\My Drive\Webcam\Webcam - Template\New Webcam Project Template.xlsx, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\%clipboard%.xlsx
	sleep, 600
	Ni := SubStr(userinput, 8, 5)
	msgbox, filecopy, I:\My Drive\Webcam\Webcam - Template\New Stream Profile Template.stream, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\dal_%Ni%_1.stream
	msgbox, run, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
	;}
	return 
	}
Here's 3 examples of input

TEST - 99966 - The other company- TL - Business Name Here - 1985 W Randolf Miller Road
TEST - 99861 - Mama'sy burgers- TL - Business Name Here - 1985 W Randolf Miller Road
TEST - 98415 - Some business name - company blab bla - 7864 this address

If first one is already made, it will recognize the other projects as the same, thus not jumping to the next command. I will have 4 letter code at start for state, and then 5 digits, that will change and can't be equal.

Last thing I have to account for is that the business name might be different in the end, which is why I'm using the asterisk. in case someone made a typo.

Let me know if you have more questions. Thanks for taking a stab at it!
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: Program Not Running, wrong Syntax?  Topic is solved

24 May 2019, 13:12

What jumps out at me right off the bat is that I doubt the following will do what you want

Code: Select all

msgbox, filecreatedir, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
[...]
msgbox, filecopy, I:\My Drive\Webcam\Webcam - Template\New Webcam Project Template.xlsx, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\%clipboard%.xlsx
[...]
msgbox, filecopy, I:\My Drive\Webcam\Webcam - Template\New Stream Profile Template.stream, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\dal_%Ni%_1.stream
msgbox, run, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
Either the msgbox, isn't supposed to be there, or you need to escape the commas in the text to be displayed in the MsgBox:

Code: Select all

msgbox, filecreatedir`, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
[...]
msgbox, filecopy`, I:\My Drive\Webcam\Webcam - Template\New Webcam Project Template.xlsx`, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\%clipboard%.xlsx
[...]
msgbox, filecopy`, I:\My Drive\Webcam\Webcam - Template\New Stream Profile Template.stream`, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\dal_%Ni%_1.stream
msgbox, run`, I:\My Drive\Webcam\Webcam - Projects\%no%\%clipboard%\
Secondly, clipboard is a special built-in variable. You shouldn't use it as a variable in your script unless you really mean to be putting stuff on/getting stuff from the Windows clipboard (and unless I'm missing something, I don't see a reason why you would intentionally be doing that?).

Third, depending on the context, I suppose the "*" I used might should be "\*" or "\*.*".

Edit: And I don't think the way you're trying to check ErrorLevel at the top is correct. If I understand you correctly, I think this is producing the results you want:

Code: Select all

;Making New Template
!z::
	InputBox, userinput, Create New Project Template, Please Enter Full Project ID of the new project you wish to create., ,300 ,150
	If ErrorLevel OR !userinput
		Return
	No:=SubStr(userinput,1,4)
	FilePath:=""
    Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" No "\" SubStr(userinput,1,15) "*.*", D
		{
		FilePath:=A_LoopFileLongPath
		Break
		}
	IfExist, %FilePath%
		{
		MsgBox, File already exists doofus!!!
		Run, %FilePath%
		}
	Else
		{
		;Start Copying files, etc.
		MsgBox, 4, Creating New Project Directory, Are you creating a new Project Directory?
			IfMsgBox, No
				Return
		
		MsgBox, filecreatedir`, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\
		Sleep, 600
		MsgBox, filecopy`, I:\My Drive\Webcam\Webcam - Template\New Webcam Project Template.xlsx`, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\%userinput%.xlsx
		Sleep, 600
		Ni:=SubStr(userinput, 8, 5)
		MsgBox, filecopy`, I:\My Drive\Webcam\Webcam - Template\New Stream Profile Template.stream`, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\dal_%Ni%_1.stream
		MsgBox, run`, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\
		}
Return
User avatar
eblanc
Posts: 68
Joined: 08 May 2019, 14:41

Re: Program Not Running, wrong Syntax?

27 May 2019, 12:04

@Sam_

Yes, this worked perfect! Sweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeetttttttt!

So I was adding the messageboxs just as part of the test, to read the file directories it was sending me to. (And also to avoid creating so many files when testing)

Can you also do a tiny explanation on why the asterisk needed to be changed?
Third, depending on the context, I suppose the "*" I used might should be "\*" or "\*.*".
Also, I think I know now but to make sure, I should ask. Adding a ' symbol next to a comma, makes that comma a visible comment instead of a separate option function? is it used anywhere else?

This is the final code.

Code: Select all

;Making New Template
^+T::
	InputBox, userinput, Create New Project Template, Please Enter Full Project ID of the new project you wish to create., ,300 ,150
	If ErrorLevel OR !userinput
		Return
	No:=SubStr(userinput,1,4)
	FilePath:=""
    Loop, Files, % "I:\My Drive\Webcam\Webcam - Projects\" No "\" SubStr(userinput,1,15) "*.*", D
		{
		FilePath:=A_LoopFileLongPath
		Break
		}
	IfExist, %FilePath%
		{
		MsgBox, 16, Overwrite Protection, The folder path already exist in the directory, cannot overwrite. Opening folder directory instead.
		Run, %FilePath%
		}
	Else
		{
		;Start Copying files, etc.
		MsgBox, 4, Creating New Project Directory, You are creating a new Project Directory. Would you like to continue?
			IfMsgBox, No
				Return
		
		filecreatedir, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\
		Sleep, 600
		filecopy, I:\My Drive\Webcam\Webcam - Template\New Webcam Project Template.xlsx, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\%userinput%.xlsx
		Sleep, 600
		Ni:=SubStr(userinput, 8, 5)
		filecopy, I:\My Drive\Webcam\Webcam - Template\New Stream Profile Template.stream, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\dal_%Ni%_1.stream
		run, I:\My Drive\Webcam\Webcam - Projects\%No%\%userinput%\
		}
Return
And Case closed!
Sam_
Posts: 106
Joined: 20 Mar 2014, 20:24

Re: Program Not Running, wrong Syntax?

28 May 2019, 09:44

eblanc wrote:
27 May 2019, 12:04
Can you also do a tiny explanation on why the asterisk needed to be changed?
Third, depending on the context, I suppose the "*" I used might should be "\*" or "\*.*".
I don't know that the change was necessary and the docs don't seem to go into that much detail on FilePattern. This suggestion was more like "If nothing else I suggested works, try this just to be sure".
eblanc wrote:
27 May 2019, 12:04
Also, I think I know now but to make sure, I should ask. Adding a ' symbol next to a comma, makes that comma a visible comment instead of a separate option function? is it used anywhere else?
` (backtick) is the default EscapeChar.

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Perry_1984, abitofmaya, Bing [Bot], Google [Bot], Gully, jbfilms1, joefiesta, JoeWinograd, MannyKSoSo, Subaru, swagfag, westlion, Xtra and 92 guests