?
Solved

Script to make file copies with different names

Posted on 2015-01-08
3
Medium Priority
?
188 Views
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
testnow_1.txt
testnow_2.txt
testnow_3.txt
.
.
.
.
testnow_95.txt

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 {
                Files.copy(src,dest);
            } catch (IOException e) {
                e.printStackTrace();
            }
          }
   }
}


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

Thanks,
0
Comment
Question by:shragi
[X]
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
  • 2
3 Comments
 
LVL 84

Accepted Solution

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

Author Comment

by:shragi
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.
0
 

Author Comment

by:shragi
ID: 40537876
never mind i got it - thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

762 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