The main problem seems to be the space between (%dir1% *.txt)
It could be
@ECHO off
title Test
set "dir1=C:UsersFamilyDesktopExample"
: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 %%X in ("%dir1%*.txt") DO echo %%~dpnX
echo Done
pause
The quotes are for avoiding problems with spaces or other special characters in the path.
EDIT:
The %%~dpnX
is for expanding the filename of %%X
to
d
=drive(C:)
p
=path(UsersFamilyDesktopExample)
n
=filename(test1) (without extension)
f
=full filename(C:UsersFamilyDesktopExampleest1.txt).
The possible modifiers are explained here FOR /?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…