Batch For Nest In file and in range

  • 8 months ago
Comment

ChatGPT
1 / 1

Sure, here's an example of using nested for loops in a Windows batch script to iterate through both a file and a range of numbers:

Suppose you have a file named filelist.txt with the following content:

file1.txt
file2.txt
file3.txt

And you want to iterate through this file and a range of numbers from 1 to 5. Here's how you can do it:

batch
@echo off

REM Iterate through the file
for /f %%A in (filelist.txt) do (
echo File: %%A
)

REM Iterate through a range of numbers from 1 to 5
for /l %%B in (1,1,5) do (
echo Number: %%B
)

In this example, the first for loop iterates through the lines in the filelist.txt file, and the second for loop iterates through a range of numbers from 1 to 5.

You can adapt this script to your specific use case by replacing the file content and the range of numbers with your actual data.