[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Why do I get an error using 'rename'?



Files returned fromn a readdir do not have any path information added, so
you probably need to add the path, e.g.:

$path = ':::healthcare.ucla.edu:pls';

foreach $file (@files) {
    if ($file =~ m/.out/) {
        ($temp = $file) =~ s/.out//;
        rename ("$path:$file", "$path:$temp") or warn "Could not rename
$file to $temp\n";
    }
} 

-K

"A foolish consistency is the hobgoblin of little minds"

> From: Robert Terwilliger <raterwil@ucla.edu>
> Date: Fri, 12 Nov 1999 16:45:29 -0800
> To: <macperl@macperl.org>
> Subject: [MacPerl] Why do I get an error using 'rename'?
> 
> Hi people.  I am trying to remove the '.out' suffix from each file in my
> directory.  Here is my code:
> 
> opendir(DIR, ':::healthcare.ucla.edu:pls:') or die 'cannot open directory';
> @files = readdir(DIR);
> closedir(DIR);
> 
> foreach $file (@files)
> {
> if ($file =~ m/.out/)
> {
> ($temp = $file) =~ s/.out//;
> rename ($file, $temp) or warn "Could not rename $file to $temp\n";
> }
> } 
> 
> ###########################
> 
> This is MacPerl console output:
> 
> # Could not rename acne.htm.out to acne.htm
> # Could not rename ageskin.htm.out to ageskin.htm
> # Could not rename arthritis.htm.out to arthritis.htm
> # Could not rename asthma.htm.out to asthma.htm
> 
> 'rename' is returning 0 and not 1.  How do I get this to work?
> 
> --
> Robert Terwilliger, M.S.
> raterwil@ucla.edu
> 
> 
> 
> # ===== Want to unsubscribe from this list?
> # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org
> 


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org