Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Script to make file copies with different names

Posted on 2015-01-08
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 84

Accepted Solution

ozo earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

808 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