Page 1 of 1

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

Posted: 18 Apr 2019, 18:25
by SvenBent
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)

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

Posted: 18 Apr 2019, 18:43
by SvenBent
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

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

Posted: 18 Apr 2019, 18:51
by JoeWinograd
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