you might change:
     my $p = `rename $old_name $new_name`;
    to
     next if ( rename($old_name, $new_name) ) ;    # implies successful rename
    print "Error: " , $! , "\n";
    printf "OldFile: %s\nNewFile: %s\n",
                    $old_name,
                    $new_name;
   
Using only Perl routines to do the work.
A thought. Seems to look right from what I can see.
 
Wags ;)

 -----Original Message-----
From: Gerald Preston [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 21, 2006 12:06
To: Wagner, David --- Senior Programmer Analyst --- WGO; [email protected]
Subject: RE: renaming files in XP

David,

 

Here is the code:

#!/perl

 

  use strict;

 

  local( *FI, *FO );

 

  my $DEBUG  = 00;

  my $DEBUG1 = 01;

  my $path   = "C:\\Documents and Settings\\Jerry\\My Documents\\My Music\\";

 

#  $path .= "NEW\\Easy Listing\\Harry Connick Jr\\" ;

  $path .= "NEW\\Country\\Reba McEntire\\" ;

 

      opendir( DIR, $path );

      my @dir = readdir( DIR );

 

my $file = "To See You";

my $file = "Sweet Sixteen";

my $file = "The Last One To Know";

 

#     foreach my $file ( @dir ) {

 

        next if $file eq "." or $file eq "..";

        print "0 $file\n" if $DEBUG;

        my $file_path = "$path$file";

        opendir( DIR, $file_path );

        my @files = readdir( DIR );

        foreach my $file ( @files ) {

 

          next if $file eq "." or $file eq ".." or $file =~ "ncd";

          print "2 $file*\n" if $DEBUG;

          if( $file =~ /m3u/ ) {

 

&m3u_check_out( "$file_path\\$file", $DEBUG1 );

#exit;

            my $file_name = "$file_path\\$file";

            print "3 $file_name*\n\n" if $DEBUG1;

            my $j = 0;

            open( FI, $file_name ) || die "$file_name $!\n";

            while( <FI> ) {

 

              next if /EXTM3U|EXTINF/;

              $j++;

#print "act $file_path\\$_";

              my $mp = /mp3/   ? ".mp3" : ".mp4";

              my $jc = $j < 10 ? "0$j"  : "$j";

              my $old_name = "$file_path\\Track No$jc$mp";

              my $new_name = "$file_path\\$_";

              next if $old_name eq $new_name;

              next if( ! -e $old_name );

print "$old_name ** $_\n";

              my $p = `rename $old_name $new_name`;

              print "$p - 4 $_\n" if $DEBUG1;

            }

            close FI;

          }

        }

#      }

 

Jerry

 


From: Wagner, David --- Senior Programmer Analyst --- WGO [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 21, 2006 1:50 PM
To: Gerald Preston; [email protected]
Subject: RE: renaming files in XP

 

    Without seeing code, the list will be guessing. As fully as you defined the setup for the writing of the file, then you will need to qualify that much to do the rename.

 

        What does the error say? ( ie, if ( ! rename(old,new) ) { print $! } )

 

Wags ;) ps a code snippet portion is almost a must for people to repsond.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Gerald Preston
Sent: Tuesday, March 21, 2006 10:46
To: [email protected]
Subject: renaming files in XP

Hi!

 

I am using version 5.8.7 on XP Pro.  I am trying a very simple thing, that is I am trying to rename a file “rename $old_name, $new_name”.  I know this a not biggie but what am I doing wrong.

 

I am not local directory that I am changing the file, is this the problem?

 

Thanks,

 

Jerry

 

 



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to