The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Email Subscription

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 717 other subscribers

For – Loop through a range of numbers | Windows CMD | SS64.com

Posted by jpluimers on 2017/06/27

Since I always forget:

for /l %1 in (1,2,200) do echo %1 >> text-%1.txt

This creates files with incremental filenames like this:

text-1.txt
text-3.txt
...
text-199.txt

–jeroen

via: For – Loop through a range of numbers | Windows CMD | SS64.com [WayBack]

4 Responses to “For – Loop through a range of numbers | Windows CMD | SS64.com”

  1. ruurd's avatar

    ruurd said

    Now do the same for 000 001 002 003 004 005 … 998 999

    • jpluimers's avatar

      jpluimers said

      Since you likely have done that before, please post the solution as a comment (;

      • Jürgen Krämer's avatar

        Jürgen Krämer said

        I think there is no way to make this a one-liner, so this is the best (batch file) I could come up with:

        @echo off
        setlocal EnableDelayedExpansion
        for /l %%i in (1,2,1000) do (
            set num=00%%i
            echo %%i > text-!num:~-3!.txt
        )
        

Leave a Comment