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

前端 未结 5 542
失恋的感觉
失恋的感觉 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:01

    %0 gives you the relative path the from the directory where the bat file was started. So if you call it

    mybats\delyourself.bat tango roger
    

    %0 will contain mybats\delyourself.bat

    del %0 works if you haven't changed your current directory.

    %~f0 exapnds to the full path to the file.

提交回复
热议问题