I am facing error when i try to delete a file using a batch file. For example say the file i want to delete is "C:\test\a.dll"
i get the folder "c:\test" from regist开发者_如何学JAVAry and then i try to append the file name using and delete it using the following command
del /s %WPINSTDIR%\a.dll
where i get WPINSTDIR from registry and it would be "C:\test"
however when i try to run the batch file i get a error saying network path found and this is the command that is executed. del /s "c:\test"\a.dll
By setting a environment path variable i found that the problem is with the 2 slashes in "c:\test" and the quotes. Anyway to get around this problem.
Thanks
Try using
pushd %WPINSTDIR%
del /s a.dll
popd
This restores the former directory.
You can remove quotes around your environment variable with the following:
%WPINSTDIR:"=%
So the following might work:
del %WPINSTDIR:"=%\a.dll
It will fail, though, if the path contains spaces.
You can also use the following:
call :del_file %WPINSTDIR% a.dll
goto :eof
:del_file
del "%~1\%~2"
goto :eof
which should work even with paths containing spaces. The ~
in %~1
removes surrounding quotes.
This might do:
set current=%CD%
CD /d %WPINSTDIR%
DEL /s a.dll
CD /d %current%
EDIT
Edited to use CD /d
and the "%CD%
-trick".
精彩评论