0

I want to copy to a new single file (Ebinds.txt) a certain value from a number of "identical" .txt files found in a folder. the files are named such as log1.txt, log2.txt, etc. and the value I am interested in is always placed in the same spot aka 22nd line, 2nd value. the part where I search for my value and copy it works fine. my problem is when I try to loop through all the files in the folder ( all I get is echo off instead of the values)

below is an example of the code I got so far when there are 4 files in my folder.

@echo off

FOR /l %%P IN (1,1,4) DO (

set InFile=C:\Users\nuca\Desktop\dock_copy_Ebind\nodV_log%%P.txt

set /a "line = 0"
for /f "tokens=2 delims= " %%L in ("%InFile%") do (set /a "line = line + 1"
if !line!==22 set thing=%%L
)
endlocal && set thing=%thing%
echo %thing% >>C:\Users\nuca\Desktop\dock_copy_Ebind\Ebinds.txt
)
Ana G.
  • 3
  • 1

1 Answers1

0

In the current code, below @echo off add setlocal enabledelayedexpansion then change your variables from %thing% to !thing!

However, you do not need to set the variable each time:

@echo off
setlocal enabledelayedexpansion
for %%a in ("C:\Users\nuca\Desktop\dock_copy_Ebind\nodV_log*.txt") do (
    set cnt=
    for /f "usebackq delims=" %%i in ("%%~a") do (
       set /a cnt+=1
       if !cnt! equ 22 echo %%i
   )
)
Gerhard
  • 22,678
  • 7
  • 27
  • 43