如何设置当前路径以执行批处理文件位置?

How to set current path to executing batch file location?

我创建了一个 windows 调度程序任务来执行 c:\codes 目录中的批处理文件,在批处理文件中我编写了命令来执行几个 jar 文件,这些文件位于执行批处理文件的位置存在,但在执行该任务时显示错误:

C:\Windows\system32>SET mypath=C:\codes\ C:\Windows\system32>java -jar CreateAttachments.jar Error: Unable to access jarfile CreateAttachments.jar

批处理文件中的内容是:

SET mypath=%~dp0 java -jar CreateAttachments.jar java -jar SendEmailsInSheduledTime.jar echo 'Task completed' exit

使用 pushd "%~dp0"cd /D "%~dp0"

打开命令提示符 window 并输入 pushd /?,然后输入 cd /? 以获取有关更改工作目录的这 2 个命令的详细信息。