Can a Windows batch file determine its own file name?

后端 未结 6 551
死守一世寂寞
死守一世寂寞 2020-12-07 11:16

Can a Windows batch file determine its own file name?

For example, if I run the batch file C:\\Temp\\myScript.bat, is there a command within myScript.bat that can de

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 11:33

    Yes.

    Use the special %0 variable to get the path to the current file.

    Write %~n0 to get just the filename without the extension.

    Write %~n0%~x0 to get the filename and extension.

    Also possible to write %~nx0 to get the filename and extension.

提交回复
热议问题