Search code examples
windowsbatch-fileduplicatesrenameincrement

Duplicate and rename by increment of 1


I have a file 00185.txt, how do I create a batch file to duplicate this file and rename to 00186.txt, then continue to duplicate another 150 times by an increment of one.

eg. original file is 00185.txt, duplicate this and rename to 00186.txt, then the next would be 00187.txt, all the way to 00300.txt.

Any help would be greatly appreciated. Thank you.


Solution

  • @echo off
    setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
    
    if not exist "00185.txt" echo Stack overflow example > "00185.txt"
    
    set first=186
    set /A last=%first% + 150
    for /L %%A IN (%first%,1,%last%) do @copy /B /Y "00185.txt" "00%%A.txt" > nul