Script to make file copies with different names

Posted on 2015-01-08
Medium Priority
Last Modified: 2015-01-08
I had a file named "testnow.txt" and i want to make this file 95 copies.. in the same folder
i want to duplicate the "testnow.txt" and rename it like

Here is the java code that made this work, but I am not sure how to write the same logic using perl.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
public class filerenametemp {
    public static void main(String[] args) {
          Path src = Paths.get("C:\\temp\\testnow.txt");
          for( int i=1;i<=6; ++i ){
            Path dest =  Paths.get("C:\\temp\\testnow_" + i + ".txt");
            try {
            } catch (IOException e) {

Can some one provide me the code with same logic in perl.

Question by:shragi
  • 2
LVL 85

Accepted Solution

ozo earned 2000 total points
ID: 40537822
use File::Copy;
copy "testnow.txt", "testnow_$_.txt" or die "Copy failed: $!" for 1..95;

Author Comment

ID: 40537871
Hi ozo - this solution is good and working,
what if my number is not always 95 and it changes based on parameter.
How do i change script for that.

Author Comment

ID: 40537876
never mind i got it - thanks

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Before you approach an Ionic Mobile App development company for developing mobile apps using the ionic framework, you must know why you should choose the framework. Let's try to understand that through this article.
In a question here at Experts Exchange, a member was looking for "a little app that would allow sound to be turned OFF and ON by simply clicking on an icon in the system tray". This article shows how to achieve that, as well as providing the same OF…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question