我想要一个批处理脚本来处理文件夹中的所有文本文档。 这是我目前为止完成的:
@ECHO off
title Test
set dir1=C:\Users\Family\Desktop\Example
:Start
cls
echo 1. test loop
echo 2. Quit
set /p choice=I choose (1,2):
if %choice%==1 goto test
if %choice%==2 exit
:test
cls
echo running loop test
FOR %%n in (%dir1% *.txt) DO echo %dir1%\%%n
echo Done
pause
我希望输出的内容是:
我想要输出的是:
running loop test
C:\Users\Family\Desktop\Example\doc 1.txt
C:\Users\Family\Desktop\Example\doc 2.txt
Done
但我得到了这个:
running loop test
C:\Users\Family\Desktop\Example\C:\Users\Family\Desktop\Example
C:\Users\Family\Desktop\Example\doc 1.txt
C:\Users\Family\Desktop\Example\doc 2.txt
Done
%%~nX
表示仅文件名(test1),而带有扩展名的文件名应写作%%~nxX
(test1.txt)。 - Artem Pdpn”是对“%%X”的修改器。因此,正如用户2nd所说,使用变量上的“n”修改器通过调用“echo %%~nX”来仅输出文件。 - Richard Le Mesurier