Advanced perl help in windows

Hi guys,
Im trying to write a perl code to do the following task.

prerequisites:-
1) some media files(say boys.mp3 or gaga.mpeg or snoop.flv) is located in C:\videos\
2) The perl code is also located in same location C:\videos\

when I execute this perl code, it should ask for a number say 100 or 200 or even 5000 for variable n and a filename that is located in C:\videos\
and then it should duplicate that file n number of times and rename all the files with some random filenames.

Say if snoop.flv is given and n=5 then it should duplicate 5 times and rename it
eg:-
aksjg.flv
ojregnos.flv
aeofasjdavsf.flv
wajgtoih.flv
lkfj.flv

please provide your input guys

thanks

What have you tried so far?

#!/usr/bin/perl 
use File::Copy;

 $filetobecopied = "myhtml.html.";
while(n<500)
{
$random_generated_name = Generate a random string here

 $newfile = $random_generated_name".html."; 
copy($filetobecopied, $newfile) or die "File cannot be copied.";
random_generated_name = " ";
}

This is basic outline.. But I did not start coding this.

How about this

 
use strict;
print "Enter File Name: ";
my $fileName = <STDIN>;
chomp($fileName);
print "Enter Number: ";
my $no = <STDIN>;
chomp($no);
if(-e $fileName)
{
        $fileName=~/(\.\w+)$/;
        my $extn = $1;
        for(my $i=0;$i<$no;$i++)
        {
                my $randFile = &genRandString();
                $randFile .= $extn;
                my $cmd = qq@cp $fileName $randFile@;
                system($cmd);
        }
}
else
{
        print "$fileName not exits\n";
}

sub genRandString
{
        my @cha=('a'..'z','A'..'Z');
        my $string;
        $string.= $cha[rand @cha] foreach(1..10);
        return $string;
}
1 Like

This might work fine with Linux... But not in windows... Because windows doesn't know about "cp"

---------- Post updated at 06:01 PM ---------- Previous update was at 05:56 PM ----------

Its working now

I replaced cp with copy(file1, file2 ) using the File::Copy module.

Thanks getmmg.