写一个bat作用是获取传入文件的名称文件可能带空格
你可以使用以下的批处理脚本来获取传入文件的名称(包括带有空格的文件名):
@echo off
setlocal enabledelayedexpansion
rem 获取传入文件的路径
set "filepath=%~1"
rem 获取传入文件的名称(包括带有空格的文件名)
set "filename="
for %%I in ("%filepath%") do set "filename=%%~nxI"
echo 文件名:%filename%
将上述代码保存为一个批处理文件(例如:get_filename.bat),然后在命令行中执行以下命令来运行脚本并传入文件路径:
get_filename.bat "C:\Example Folder\example file.txt"
脚本将会输出传入文件的名称(包括带有空格的文件名):
文件名:example file.txt
原文地址: http://www.cveoy.top/t/topic/icLc 著作权归作者所有。请勿转载和采集!