I need to get the directory path of the .exe file ( created using Ctrl+F9 ) in my script to get additional files.
I keep some config files inside the directory of .exe itself and I need to get those without hardcoding the path.
Suppose a user runs my .exe from C:\Users\<userName>\Documents\<appName> and another user may run it from some other directory so, Is there any way that I get the Parent directory path of the .exe?
Get the parent directory path of the exe file
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 13
- Joined: Tue Oct 06, 2020 6:28 pm
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Get the parent directory path of the exe file
This is how I do it:
I also get the volume letter this way. Change how many steps up in the hierarchy you want your root to be by setting the ROOT_PATH_STOP variable.
Code: Select all
SRT>GET_ROOT_PATH
Let>TEMP=%SCRIPT_DIR%
Separate>TEMP,\,TEMP_ARRAY
Let>ROOT_PATH=
Let>k_stop=TEMP_ARRAY_count-ROOT_PATH_STOP
Let>k=0
Repeat>k
Let>k=k+1
Let>TEMP_LEVEL=TEMP_ARRAY_%k%
ConCat>ROOT_PATH,TEMP_LEVEL
IfNot>k=k_stop
ConCat>ROOT_PATH,\
Endif>
Until>k=k_stop
MidStr>ROOT_PATH,0,1,VOLUME_LETTER
DelArray>TEMP_ARRAY
END>GET_ROOT_PATH
Let>ROOT_PATH_STOP=1
GoSub>GET_ROOT_PATH
Re: Get the parent directory path of the exe file
Long story short. The variable Script_Dir will contain the location from which your executable was run.
-
- Newbie
- Posts: 13
- Joined: Tue Oct 06, 2020 6:28 pm