Making multiple copies of one file… in Windows
It took me a long time to figure this out, but once I did, it proved very useful for a particular project. I was not able to find a free program that would create multiple copies of one file for me, and I didn’t want to mess around with anything that seemed too complicated (scripting). Doing it manually in Windows was simply too stupid, frankly; and Windows doesn’t have Automator, like Mac. But I discovered that this can be done from the Windows command line.
All you need is one copy of your file, named 1 (dot) extension. In my case, it was 1.jpg.
Then you bring up the command window, go into the folder where the file is located, and type this command:
for /l %f in (1,1,800) do copy 1.jpg %f.jpg
You can change 800 to however many copies you need. So in that example, the command would have generated 800 files, named sequentially from 1.jpg to 800.jpg. Super fast! Basically, it’s a loop process of the copy command.
I figured this out thanks to reading this thread at Webmaster World, which seriously saved me a lot of time and effort. Makes me want to learn more cool command line operations. One day…
This command helped me a lot in a recent project when I needed to copy large numbers of files programatically. However, there are a few things to point out.
You do not have to be in the directory you’re copying files in. You also do not have to have your files named with only their sequence. For instance, my files are named fileName_sequence. I also have some files that need to be copied and some that need to be created. Copied files may start at any number. So, assume I need to copy the 65th through 165th files from the 64th file. In that case, my command would look like this:
for /l %f in (65,1,165) do copy filename_64.jpg filename_%f.jpg
I originally thought the third argument (165) should be 100 and that would make the OS output 100 copies. But, that is just the upper bounds of the sequence. So, if you want 100 copies, you need to add your starting copy to the value you want to come up with 165.
Thanks for finding this command and publishing it. Once I played with a bit, it works great for my purposes and speeds up my application substantially.
Is it possible to insert the sequence to the beginning? I have a need to do this with inventory numbers, but our naming convention is currently -.pdf
Yes, try putting the %f wherever you want the number to go.
I completely forgot I had this site until I got an email with your comment today. I’m glad it helped you and thanks for the tips.
Thank you
This was sweet. Any ideas on how to copy a single file using a list of filenames? For instance I have source.pdf and I’d like to copy that to:
first_source.pdf
another_source.pdf
blah.pdf
etc.pdf
I have an array of a ton of files that are being used in an app. For testing, I’d like to just create those files using a sample. The filenames are in a DB but I can get them into an array.
Thanks. The only suggestion I have for renaming a whole bunch of files is a program called Fezzik. I actually wrote about it here: http://www.heinovision.com/useful/2011/05/fezzik-totally-awesome/. It’s not as elegant as what you are asking for, but it definitely gets the job done in a fairly simple way.
Thanks for sharing the method! I need to constantly copy manually so this would be of big help . I’ve tried the line code in my windows cmd but encountered this message:
/1 was unexpected at this time.
I replaced it with the filename to copy but it’s still the same. Not sure if you can advice?
Hi SW,
I think the problem is that it’s an “L” and not a “1” that needs to be used in the “/l” part. Hope this helps.
This command works just as expected.!Thank you for Sharing this
Awesome Work…
Thank you for this. Is there a way to set up the numbering to be two characters? For example, I want my copied files to be Filename-01.ext, Filename-02.ext, etc. instead of Filename-1.ext, Filename-2.ext, etc.
I was able to modify it to include the filename easily, but I’m not sure how to get the numbers to default to two positions.
Sorry, I don’t know the answer to this one.
These instructions worked perfectly! Thanks so much! I looked up Fezzik, but it hasn’t been updated in a looooong time.
Worked beautifully! Verily i bow before you!
I am getting an error while running this command “The system cannot find the file specified.”
If anybody help me out in this. Please reply.
Thanks in advance!
Make sure you’re in the same folder where your file is located, and also check to make sure that you’re using the correct file name. Make sure you replace my fake filename “1.jpg” with whatever your filename is and also change the file extension to whatever your file extension is. Good luck.
Sweet solution for me to make 300 copies of a single file. Thank you.
This is magnificent. It saved me hours. The internet is an amazing thing. Thank you.
Thanks for your help, your code is saving my life.
This helped me a lot. Thanks
Cool, this has helped me a lot
Hi everyone, this solution was amazing. Thank you so much for the question, original answer, and clarifying comments.
For anyone looking to append certain names to slightly change a file name in additional copies, here is the solution I used, which was tailored from the original provided here.
for %f in (name1, name2, name3, name4, name5) do copy “Original Generic File Name.pdf” “%f Original Generic File Name.pdf”
This code will result in 5 new copies of the original file. name1 Original Generic File Name.pdf, name2 Original Generic File Name.pdf, and so on.
Many many thanks!
How can i modify your code in order to have ”Original file name name1” instead of ”name 1 original file name” ? Basically to have the new word/number on the left.
Thanks, very helpful for a prank! made 800 identical pictures barring one with a curly moustache and set someones desktop backround to display the images. would have been tedious withoput your help!