set command inside for loop does not work
Posted: 15 Aug 2020 05:48
I reposted corrected version of code, as soon as approved it will post
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
FOR /F "usebackq tokens=*" %%G IN ("%_FilePath%%_WrkFile%") DO (
set _LineChk=%%G
set _NewRec=!_LineChk!
set base=!_NewRec!
set left1=!base:(=" & set "right1=!
set left2=!base:.=" & set "right2=!
set left1=!left1: =!
set right2=!right2: =!
set right=
set whole=!left1!.!right2!
if !firstsw!==y set savname=!whole!
rem echo 222 savlinechk===!whole=== save name===!savname!===
if !whole! == !savname! (
rem SET _NewRec=!_LineChk!
set _NewRec=!_NewRec:~0,-1!
echo !_NewRec!
)
set firstsw=n
set savname=!whole!
echo 222savlinechk===!whole!=== save name===!savname!===
) >> "%_FilePath%%_FileName%"
Code: Select all
setlocal DisableDelayedExpansion
>"out.txt" (
FOR /F "usebackq tokens=*" %%G IN ("test.txt") DO (
FOR /F "delims=(" %%H in ("%%~nG") do set "basename=%%H"
set "extension=%%~xG"
setlocal EnableDelayedExpansion
echo !basename:~,-1!!extension!
endlocal
)
)