1.

Solve : use of SET in FOR?

Answer»
I am making list of folders I am LOOKING having name 2000 it working fine with CODE

Code: [Select]FOR /F "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO echo %%I IN %G\%%H>> L2.txt
Some reason I can't get this work with SET to get name without 2000 word

Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set "NY=%NY:2000=%"
)
echo "%NY%" IN %%G\%%H>> L2.txtIn this case you can move the line that changes the variable out of the loop. To change a variable inside a loop you need to use delayed expansion and the !variable! syntax instead of %variable%

Code: [Select]FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set g=%%G
set h=%%H
)
set "NY=%NY:2000=%"
echo "%NY%" IN "%g%\%h%">> L2.txt
This example uses delayed expansion (and be aware that ! characters in the TEXT are an issue)

Code: [Select]@echo off
setlocal enabledelayedexpansion
FOR /f "tokens=1-3 delims=\" %%G IN ('DIR /b /a:d "C:\TEST" ^| find "*2000" ') DO (
set NY=%%I
set "NY=!NY:2000=!"
echo "!NY!" IN %%G\%%H>> L2.txt
)


Discussion

No Comment Found