copying files in a dir

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kriz4321
    New Member
    • Jan 2007
    • 48

    copying files in a dir

    Hi all,
    I have some files stored in an array say my array I have to read each file from the array and if the files ends with .raz I need to copy.

    I need to copy the file from /home/kriz to /home/kriz/temp.iam working in unix environment ,as Iam new to perl can anyone say me how to check if it is a file and then how to check to ends with raz...

    thanks
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    [CODE=perl]
    if ($foo =~ /\.raz$/) {
    # do something
    }
    [/CODE]

    Comment

    • savanm
      New Member
      • Oct 2006
      • 85

      #3
      This is another idea

      Store the .raz file in ur Array...

      [CODE=perl]
      my $path = getcw();
      $path =~ s|\\|/|sg;
      opendir(DIR, $path) or die "Can't opendir $path: $!";
      my @raz = grep {/\.raz/} readdir(DIR); # Here U Get only .raz file in ur array
      [/CODE]

      Otherwise Check like this
      Suppose ur Array name is @foo

      [CODE=perl]
      foreach $foo (@foo) {
      if ($foo=~/\.raz$/) {
      # then do wt ever u want
      }
      }
      [/CODE]

      Navas
      Last edited by miller; May 23 '07, 03:54 PM. Reason: Code Tag and ReFormatting

      Comment

      • savanm
        New Member
        • Oct 2006
        • 85

        #4
        [CODE=perl]
        use File::Copy;
        use Cwd;

        my $path = getcwd();
        $path =~ s|\\|/|sg;
        opendir(DIR,$pa th) or die "Can't opendir $path: $!";
        my @raz=grep {/\.raz/} readdir(DIR);

        foreach $raz (@raz) {
        print "$raz\n";
        $new = "$path/new";
        copy("$path/$raz",$new);
        }
        closedir(DIR);
        [/CODE]


        Hi the above code is a sample code for copying the files from the current path(suppose c:/temp/) to (c:/temp/new)...

        Navas.M
        Last edited by miller; May 23 '07, 03:56 PM. Reason: Code Tag and ReFormatting

        Comment

        Working...