Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch File: Error in relative path , one level up from the current directory

I am new to the batch script programming.Getting error while executing batch file if I give the relative path. I have following folder structure

Script folder - C:\batch\script\ServiceRegister.bat
Bin path - C:\batch\bin\ERecruitGenerateReportsWindowsService.exe

ServiceRegister.bat Batch file –

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0%~1\bin\ERecruitGenerateReportsWindowsService.exe

When I execute ServiceRegister.bat file I got the error:

Exception occurred while initializing the installation:
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\batch\script\bin\ERecruitGenerateReportsWindowsService.exe' or one of its dependencies. The system cannot find the file specified.

I am using “%~dp0%~1” to go one level up in the directory still it gets its current path.

%~dp0%~1 - C:\batch\script\  

I need the C:\batch\ path. How I can get this path? It works fine If I give the absolute path -

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe
like image 317
user2323308 Avatar asked Dec 26 '22 02:12

user2323308


1 Answers

Your attempt to use %~1 to go up one level in the directory structure is inventive and totally invalid syntax. The proper syntax is just as simple - use ..\.

A leading \ is not required because %~dp0 ends with a \.

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0..\bin\ERecruitGenerateReportsWindowsService.exe
like image 194
dbenham Avatar answered Dec 31 '22 18:12

dbenham