【问题标题】:Batch File: Error in relative path , one level up from the current directory批处理文件:相对路径错误,从当前目录上一级
【发布时间】:2013-06-06 11:23:37
【问题描述】:

我是批处理脚本编程的新手。如果我提供相对路径,则在执行批处理文件时会出错。 我有以下文件夹结构

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

ServiceRegister.bat 批处理文件——

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

当我执行 ServiceRegister.bat 文件时出现错误:

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.

我正在使用“%~dp0%~1”在目录中上移一级,但它仍然获得当前路径。

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

我需要 C:\batch\ 路径。我怎样才能得到这条路? 如果我给出绝对路径,它就可以正常工作-

%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe C:\batch\bin\ERecruitGenerateReportsWindowsService.exe

【问题讨论】:

    标签: windows batch-file path


    【解决方案1】:

    您尝试使用%~1 在目录结构中上一级的尝试具有创造性且语法完全无效。正确的语法同样简单 - 使用 ..\

    不需要前导 \,因为 %~dp0\ 结尾。

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

    【讨论】:

      猜你喜欢
      • 2014-09-03
      • 2013-06-08
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      相关资源
      最近更新 更多