windows在bat文件代码中取盘符和文件夹等路径命令和变量

[电脑] 2024-04-27 圈点131

摘要:windows在bat文件代码中取盘符和文件夹等路径命令和变量,作用用法:在一个.bat 文件中,可以使用上面这些变量来获取当前文件所在的盘符、文件路径,文件名等内容。

windows在bat文件代码中取盘符和文件夹等路径命令和变量

echo 当前盘符:%~d0
echo 当前盘符和路径:%~dp0
echo 当前批处理全路径:%~f0
echo 当前盘符和路径的短文件名格式:%~sdp0
echo 当前CMD默认目录:%cd%
echo 目录中有空格也可以加入""避免找不到路径
echo 当前盘符:"%~d0"
echo 当前盘符和路径:"%~dp0"
echo 当前批处理全路径:"%~f0"
echo 当前盘符和路径的短文件名格式:"%~sdp0"
echo 当前CMD默认目录:"%cd%"
pause


作用用法:在一个.bat 文件中,可以使用上面这些变量来获取当前文件所在的盘符、文件路径,文件名等内容。

bat示例截图:

bat_sample.jpg



英文解释:

%n contains the arguments used to invoke the file: %0 is the path to the bat-file itself, %1 is the first argument after, %2 is the second and so on.

 ~d is drive.

 ~p is the path (without drive).

 ~n is the file name.

 ~dp is drive+path.

 ~t is the timestamp.

 ~z is the size.

 


bat  

感谢反馈,已提交成功,审核后即会显示