[英]Change batch file directory in system32 to CMD command execution point
So basically I have a .bat that is inside my System32 folder. 所以基本上我在System32文件夹中有一个.bat。 This batch file accepts a parameter input, this input is a file.
此批处理文件接受参数输入,此输入是文件。 I wanted it to be that I could open my Command Prompt, and for example do
我希望我可以打开命令提示符,例如
batchfile text.txt
And it would pass test.txt into batchfile.bat. 然后它将test.txt传递到batchfile.bat中。 Obviously for my terminal to do this it needs to be in System32.
显然,对于我的终端而言,它必须位于System32中。 That is where my issue is.
那是我的问题所在。 Because the batch file is in System32, when executing the command, it changes my directory to System32.
因为批处理文件在System32中,所以在执行命令时,它将目录更改为System32。
However the parameter I give it is a file. 但是我给它的参数是一个文件。 And when the command is executed and it changes the directory to System32, obviously it can no longer access the file.
并且,当执行该命令并将目录更改为System32时,很显然它将不再能够访问该文件。
How can I get around this? 我该如何解决?
Before you change directories, expand the filename to its fully-qualified filename and then reference it that way: 在更改目录之前,将文件名扩展为其完全限定的文件名,然后以这种方式引用它:
@echo off
for %%F in (%1) do set USR_REQFNM=%%~dpnxF
C:
cd \Windows\System32
echo The requested file is "%USR_REQFNM%"
goto ENDIT
REM Cleanup
:ENDIT
set USR_REQFNM=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.