Solved

Script to make file copies with different names

Posted on 2015-01-08
3
179 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
  • 2
3 Comments
 
LVL 84

Accepted Solution

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

Author Comment

by:shragi
Comment Utility
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
Comment Utility
never mind i got it - thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now