Gang,

I'd like to rename the existing files in a directory to "filename.txt"  The
files have no extensions, and have names like:

B0724 B0834 B1236 B1356 B1370
A0012 A0036 A0050 A0120 A0302 A0310 rename1.pl
....
Ynnnn
Znnnn

I pulled a sample of files over to a test directory on my desktop and I'm
trying to run my 'rename1.pl' script within the directory.

I can print a file listing with this:

  1  #!c:/perl/bin/perl -w
  2  use strict;
  3
  4  my $msds_files = "c:/winnt/profiles/myprofile/desktop/perl/test/";  #
went with forward slashes on NT
  5  opendir( MSDS, $msds_files ) or die "can't opendir $msds_files: $!";
  6  while ( defined( $msds_files = readdir(MSDS) ) ) {
  7      next if $msds_files =~ /^\.\.?$/;    # skip . and ..
  8      print "$msds_files\n";    # prints the dir list
  9  }
 10
 11  closedir(MSDS);
 12

this:

.rename1.pl.swp
A0012
A0036
A0050
A0120
A0302
A0310
rename1.pl
rename1.pl.tdy
rename1.pl~

Looking at LPfWin32 and the Perl Cbook got me started, but I'm bogged down
now. There seem to be some ready made solutions in Perl Cbook (ch. 9)

#foreach $file (@NAMES) {
#    my $newname = $file;
#    # change $newname
#    rename($file, $newname) or  
#        warn "Couldn't rename $file to $newname: $!\n";
#}
#

I also think I might need to use the append assignment operator?  

## .= ".txt"'  

I think where I'm getting stumped is the foreach example uses an array where
I've been working with a scalar variable?

Rob
--
Rob McCormick
[EMAIL PROTECTED] / Meridian - M2151



Reply via email to