Getting folderpath from filepath. ( or run exe in its own folder) Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Getting folderpath from filepath. ( or run exe in its own folder)

18 Apr 2019, 18:25

my script is asking the user to select a file to run by this

FileSelectFile, Var_FileRun

Then later on in the script i run the file like this

run, %Var_FileRun%

However this make the file run in the A_workdir and i need it to run from it location folder.


Is there a way to make the run command always start the file in it own folder. or a simple way to trim the Var_FileRun to only contain the folder location of the file
E.g.:
Var_FolderRun := FunctionTrim(Var_FileRun)
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: Getting folderpath from filepath. ( or run exe in its own folder)  Topic is solved

18 Apr 2019, 18:43

figured it out. posting incase other is going to need it

Var_FolderRun := SubStr(Var_FileRun, 1, InStr(Var_FileRun, "\", , Startingpos := 0))

It usses InStr to find the locationg of the lats \ in the path
that is then passed on to SubStr as the lengs of the string of the path to put into Var_FolderRun
User avatar
JoeWinograd
Posts: 1352
Joined: 10 Feb 2014, 20:00

Re: Getting folderpath from filepath. ( or run exe in its own folder)

18 Apr 2019, 18:51

Since your FileSelectFile,Var_FileRun command has no params beyond the OutputVar, Var_FileRun will contain the full file path, as stated in the FileSelectFile doc. If you want to split Var_FileRun into its components, read the SplitPath doc, which shows that you can do this:

SplitPath,Var_FileRun,OutFileName,OutDir,OutExt,OutNameNoExt,OutDrive

Regards, Joe

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, Xeo786 and 208 guests