none
making multiple copies of a file RRS feed

  • Question

  • I need to make multiple copies of a file, example: test.txt file but the and then rename them to test1.txt, text2.txt, etc couldn't find and easy way to script
    Tuesday, May 27, 2014 7:43 PM

Answers

  • If you're just trying to append a sequential number to the end of the file name you could use this :

    for /L %%i IN (1,1,10) do copy text.txt text%%i.txt

    which in this example will copy text.txt to text1.txt, text2.txt etc through to text10.txt.

    The bit in brackets controls the start value, the increment and the end value, and then you simply adjust the bit at the end to relate to the filename you're renaming.

    • Proposed as answer by FZB Tuesday, May 27, 2014 9:08 PM
    • Marked as answer by arnavsharmaModerator Wednesday, June 4, 2014 9:53 AM
    Tuesday, May 27, 2014 8:53 PM

All replies

  • If you're just trying to append a sequential number to the end of the file name you could use this :

    for /L %%i IN (1,1,10) do copy text.txt text%%i.txt

    which in this example will copy text.txt to text1.txt, text2.txt etc through to text10.txt.

    The bit in brackets controls the start value, the increment and the end value, and then you simply adjust the bit at the end to relate to the filename you're renaming.

    • Proposed as answer by FZB Tuesday, May 27, 2014 9:08 PM
    • Marked as answer by arnavsharmaModerator Wednesday, June 4, 2014 9:53 AM
    Tuesday, May 27, 2014 8:53 PM
  • if you run Keith's command directly from the command line, only use one %, if you save it inside a batch file and run that, you need the %%
    Tuesday, May 27, 2014 9:09 PM
  • Thank you, worked perfectly on Windows 7 with one "%"
    Saturday, June 22, 2019 5:34 PM
  • Thanks worked great.  If I wanted 1 to 1000 starting at 001, 002, etc.... can the %i value be formatted?  I suppose I could go from 1000 to 1999 if lexicographic order was what I was after.  I know ordering in Winows can be controlled  (numerical vs. literal) but that doesn't always help if opening the folder from another application.  Thanks again!
    Saturday, June 22, 2019 5:50 PM