in reply to Renaming files in dir

From the File::Copy documentation:
"The move function also takes two parameters: the current name and the intended name of the file to be moved."

Seems to me that you are creating a new filename (in $file) but not retaining the old file name for the first parameter to 'move'.

You should test the return value for an error, for example:
move ($oldname, $newname) or die "Unable to rename '$oldname' to '$newname': $!";

Replies are listed 'Best First'.
Re^2: Renaming files in dir
by larus (Acolyte) on Mar 19, 2009 at 09:17 UTC
    Well, I tried this
    foreach my $file (@fileet) { my $newfile = 0; $newfile =~ s/ä/ä/g; $newfile =~ s/ö/ö/g; move("$file", "$path/$newfile"); }
    but this produces no output. What I'm doing wrong here?
      foreach my $file (@fileet) { my $newfile = $file; $newfile =~ s/ä/ä/g; $newfile =~ s/ö/ö/g; move("$file", "$path/$newfile"); }
        Thanks, there is still a problem, because this code does not rename those files. What should I do?
        #!/bin/perl #usage: #C:\Perl>perl Print_dir_sizes.pl "C:/Perl/" use warnings; use strict; use File::Copy; my $path = $ARGV[0]; die "You must supply a full directory path" unless (-e $path && -d $pa +th); my @dirs; opendir(DIR, $path) || die "can't opendir $path: $!"; my @fileet = grep { -f "$path/$_" } readdir(DIR); closedir(DIR); foreach my $file (@fileet) { my $newfile = $file; $newfile =~ s/ä/ä/g; $newfile =~ s/ö/ö/g; move("$file", "$path/$newfile"); }