Relative path in BAT script

Here is my own program folder on my USB driver:

Program\ run.bat bin\ config.ini Iris.exe library.dll etc. 

I want to use run.bat to run my Iris.exe

I can not use this: F: /Program/bin/Iris.exe as a shortcut, because sometimes it does not give me the driver name F (E, G)

What do I need to write to the bat file to work like a charm? I tried this in a BAT file:

  ˝\bin\Iris.exe˝ 

He does not work: (

+117
exe cmd relative-path batch-file relative drive shortcut
Feb 18 '13 at 12:43
source share
5 answers

Use this in your batch file:

 %~dp0\bin\Iris.exe 

%~dp0 resolves the full path to the folder where the script package is located.

+257
Feb 18 '13 at 18:28
source share

You can get all the necessary file properties using the following code:

 FOR %%? IN (file_to_be_queried) DO ( ECHO File Name Only : %%~n? ECHO File Extension : %%~x? ECHO Name in 8.3 notation : %%~sn? ECHO File Attributes : %%~a? ECHO Located on Drive : %%~d? ECHO File Size : %%~z? ECHO Last-Modified Date : %%~t? ECHO Parent Folder : %%~dp? ECHO Fully Qualified Path : %%~f? ECHO FQP in 8.3 notation : %%~sf? ECHO Location in the PATH : %%~dp$PATH:? ) 
+35
Feb 18 '13 at 23:28
source share

I found that %CD% indicates the path from which the script was called, and not the script path, however %~dp0 will provide the path to the script itself.

+18
May 3 '17 at 11:13
source share

You should be able to use the current directory.

"% CD%" \ Bin \ Iris.exe

+12
Mar 17 '17 at 12:26
source share

or bin\Iris.exe (without a leading slash - because it means starting right from the root)
or \Program\bin\Iris.exe (full path)

+4
Feb 18 '13 at 12:52
source share



All Articles