Perl script to Rename Files

# written in DOS Perl but commands are similar
# Renames files in a directory
# This one moves some of the chars in the original file to other spots
# and adds a '19" to make it Y2K compliant
#
# Old file: AL0798CT  New file: CTAL199807.html
# You must be in the directory containing files to rename
# but this file can be in some other dir

					# Read files into array
opendir(DIR,'.') || die "Can't open current directory";
@filenames = readdir(DIR);
closedir(DIR);

for (@filenames)
  {
  next if $_ eq '.';    	# skip directory info
  next if $_ eq '..';	
  next if $_ eq $0;		# skip this file
  $fname = $_;
  $newname = substr($fname,6,2).substr($fname,0,2)."19".substr($fname,4,2).substr($fname,2,2).".html";

# run without the system command, just the print first to see if you guessed right.
  print " FNAME=$fname  NEWNAME=$newname \n";
  system "ren $fname $newname";
  }