anyway to make sure current directory is a certain filepath Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
wryyymuda
Posts: 32
Joined: 21 Sep 2018, 21:43

anyway to make sure current directory is a certain filepath

29 May 2019, 14:51

i need my ahk script to move itself to C:\Users\%A_username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
so it starts upon login, i have done this but i also need to make sure the file is actually there.

so let's say i run it on my desktop, it should be able to detect its not where it needs to be, copy itself to the startup and then on startup check if its there and do the desired program.

Code: Select all

username = %A_username% ;gets the username
startup = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup ;moves startup dir to a simpler to use variable, purely for simplicity
scrpitdir = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\%A_scriptname% ;same reason as desireddirs description
; if fileexist (%scriptdir%) ;should make sure the script is where it needs to be
if (A_workingdir = "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup")
{
msgbox, it works ; for testing
exitapp
}
else 
{
msgbox, no ; for testing
filecopy, %A_scriptname%, %startup% ; copys the current file to startup
exitapp
}
exitapp
return
this is what i have so far, it can move itself if its not where it needs to be but on startup(im just running it from the startup folder)it doesnt detect its where it needs to be. what am i doing wrong?
wryyymuda
Posts: 32
Joined: 21 Sep 2018, 21:43

Re: anyway to make sure current directory is a certain filepath  Topic is solved

29 May 2019, 16:27

so i fixed most of the problems, commented what most lines do, and have it actually work, works for any file path as long as it gets filled in correctly.

Code: Select all

username = %A_username% ;gets the username 																		; gets the username and stores it in a easier to use variable
startup = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 					;moves startup dir to a simpler to use variable, purely for simplicity
scrpitdir = C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\%A_scriptname% 	;same reason as desireddirs description
dir_arr := StrSplit(A_workingdir, "\", "`t" ":") 																; creates an array which can be used to check if the filepath is correct or not
loop % dir_arr.MaxIndex() 																						; loops as many times as there are array values
	{
	dir_var := dir_arr[A_index] 																				; mives the current array value to a more useable variable 
	strt = startup 																								; sets a variable named startup because i cant use startup twice without it being an array which i will not do
	if (dir_var = strt)  																						; checks if the current directory is startup, (if any file in the full working dir is called startup then the program will run, i havent found a way around this
		{
		;msgbox, %dir_var% it worked 																					; testing purposes
		;//  code here
		}
		else 																									; if the dir is not good it copies the script to desired location
		{
		;msgbox, fail 																							; testing purposes 
		filecopy, %A_scriptname%, %startup% 																	; copys the current file to startup ; copies the ahk script to the desired directory 
		}
	}
exitapp
return
feel free to use it as long as i get the credit for writing the check and move part.

Return to “Ask For Help”

Who is online

Users browsing this forum: 2ndprotocol, Bing [Bot], boiler, frosse, Frosti, teadrinker, Zamfir and 67 guests