Windows 批处理文件可以确定自己的文件名吗? [英] Can a Windows batch file determine its own file name?

查看:23
本文介绍了Windows 批处理文件可以确定自己的文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 批处理文件能否确定自己的文件名?

Can a Windows batch file determine its own file name?

例如,如果我运行批处理文件 C:TempmyScript.bat,在 myScript.bat 中是否有可以确定字符串myScript.bat"的命令?

For example, if I run the batch file C:TempmyScript.bat, is there a command within myScript.bat that can determine the string "myScript.bat"?

推荐答案

是的.

使用特殊的 %0 变量来获取当前文件的路径.

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

编写 %~n0 以获取不带扩展名的文件名.

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

写入 %~n0%~x0 以获取文件名和扩展名.

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

也可以写%~nx0来获取文件名和扩展名.

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

这篇关于Windows 批处理文件可以确定自己的文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆