relative path in BAT script

2019-01-29 19:55发布

Here is my own program folder on my USB driver:

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

I would like to use run.bat to start my Iris.exe

I cannot use this: F:/Program/bin/Iris.exe like a shortcut, because sometimes, it not gives me F driver name (E, G)

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

 ˝\bin\Iris.exe˝ 

It is not working :(

5条回答
闹够了就滚
2楼-- · 2019-01-29 20:33

Use this in your batch file:

%~dp0\bin\Iris.exe

%~dp0 resolves to the full path of the folder in which the batch script resides.

查看更多
聊天终结者
3楼-- · 2019-01-29 20:37

I have found that %CD% gives the path the script was called from and not the path of the script, however, %~dp0 will give the path of the script itself.

查看更多
趁早两清
4楼-- · 2019-01-29 20:37

either bin\Iris.exe (no leading slash - because that means start right from the root)
or \Program\bin\Iris.exe (full path)

查看更多
狗以群分
5楼-- · 2019-01-29 20:45

You should be able to use the current directory

"%CD%"\bin\Iris.exe

查看更多
Lonely孤独者°
6楼-- · 2019-01-29 20:54

You can get all the required file properties by using the code below:

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:?
)
查看更多
登录 后发表回答