Page 1 of 1

How to duplicate easily one file in N copies ?

Posted: 04 Nov 2010 09:34
by jjk
Hi all,
I 'd like to copy the selected file (or even the selected files) in the same directory.
Say that the source is dir\Myfile.txt
I want to get dir\Myfile-01.txt, dir\Myfile-02.txt, dir\Myfile-03.txt, and so on.

While dir\Myfile.txt is selected, I hit Ctrl-D (Copy Here with number). That's OK.
dir\Myfile-01.txt is created, but dir\Myfile-01.txt is now selected.
So, if I want to get dir\Myfile-02.txt I have to first select dir\Myfile.txt before hitting Ctrl-D.
If I want duplicate dir\Myfile.txt say 100 times, it is a pain to have first to select the original file before duplicating it.

Perhaps a script could realize that ?
If not, I'd like an option to have, in case of duplicating in place, the target selected rather than the source. So I'd hit Ctrl-D 100 times and that's all.

Thanks in advance.

Re: How to duplicate easily one file in N copies ?

Posted: 04 Nov 2010 12:07
by zer0
This ought to do it. It makes 100 copies, as per your question...

Code: Select all

$initialFile = "<curitem>";
    $count = 0;
    while ($count < 100) {
      new(, , "$initialFile");
      $count++;
    }

Re: How to duplicate easily one file in N copies ?

Posted: 04 Nov 2010 12:46
by SkyFrontier
For the sake of usability, I'd like to suggest a little interface for having an easier control over the total of files to be created.

-will ask user on the total number of files to be created, then replicating at that given value.

Code: Select all

   input $total, "This will replicate current selected item. Please enter the total of files to be created:", "99";
   $initialFile = "<curitem>";
    $count = 0;
    while ($count < $total) {
      new(, , "$initialFile");
      $count++;
    }
Thank you, zer0! This will be great for creating test dummy files with little effort.

Re: How to duplicate easily one file in N copies ?

Posted: 04 Nov 2010 14:27
by jjk
Thank you both.
It works very well and it is very useful and handy. 8)