Does a bat file know its name and can it delete itself

前端 未结 5 551
失恋的感觉
失恋的感觉 2020-12-07 02:37

At some point in my script, I\'d like the bat script to delete itself. This requires that the script know its name and then to use that name to delete itself. Is this possib

5条回答
  •  情话喂你
    2020-12-07 03:16

    For me it was important, that I have no errorLevel 1 after I exited the batch file. I found an suitable and easy answer this way: DeleteMyself.cmd:

    START CMD /C DEL DeleteMyself.cmd
    

    Test batch if DeleteMyself.cmd is returning errorLevel 0. TestDeleteMyself.cmd:

    call DeleteMyself.cmd
    echo Errorlevel: %errorLevel%
    

提交回复
热议问题