|
Answer» I'd like to extract a string (STARTING at pos 27, length 25 chrs) from MULTIPLE text FILES and log it to another file (log.txt).
The script below works fine to catch that data from within one specific file (file.txt). It even leaves out any empty spaces inside the string...
Code: [Select]echo on setlocal enabledelayedexpansion for /f "tokens=* delims= " %%i in (c:\tmp\file.txt) do ( set str=%%i set id1=!str:~26,25! set id1=!id1: =! echo !id1! >> c:\tmp\log.txt ) endlocal Now to my problem: How do CHANGE the script so it scans a directory (c:\tmp) with thousands of files to perform the same operation with files that has filenames such as invoice_[NR].txt?
Any help is appreciated Untested:
Code: [Select]@echo off setlocal enabledelayedexpansion for %%a in (*.txt) do ( for /f "tokens=* delims= " %%i in ( ' type "%%a" ' ) do ( set "str=%%i" set id1=!str:~26,25! set id1=!id1: =! >> c:\tmp\log.txt echo !id1! ) ) endlocalfoxidrive, you nailed it. Thanks!
|