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

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



On 11/12/99 at 4:45 PM, Robert Terwilliger wrote:

: 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?
: 
: 

Most likely because your current working directory does not contain the files in
your list.

You need to either use chdir() like this:

    closedir(DIR);

    chdir(':::healthcare.ucla.edu:pls:');

    foreach $file (@files) {...

or apppend that path to each file name:

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

    foreach $path.$file (@files) {...

Don



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