Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

education about perl, part 2

I'm working on a perl script that is going to grab a bunch of files from a directory, rename them according to what they are called, create a new timestamp-based folder and move the newly renamed files into the new time-stamped based directory.  I understand software concepts, but the regular expression stuff is still very difficult for me.

I am now creating the directory and reading the source directory and successfully moving the files.  Now I need to rename the files.

Here's the file names before rename:
Server01__NEWFIRST.2005.02.14.16.10.rpy
Server04__NEWFIRST.2005.02.14.15.28.rpy

Here's the desired file name after the rename:
Server01__NEWFIRST.2005.02.14.16.10.rpy -> NovOval_2005-02-14_16-10.rpy
Server04__NEWFIRST.2005.02.14.15.28.rpy -> IntRC_2005-02-14_15-28.rpy


Now i have a bunch of other files with different server names but this should give you the gist of what I'm trying to do.  I'm currently looping through the directory and grabbing each file individually, hoping to rename them according to the convention above, and then copy them over.

Any suggestions?  Thanks in advance!
0
will1383
Asked:
will1383
1 Solution
 
ozoCommented:
my %tr=(
Server01_ => 'NovOval',
Server04_ => 'IntRC',
);
my $servers=join',',keys %tr;
for( <{$servers}_NEWFIRST.*.rpy> ){
   (my $n=$_) =~ s/(Server\d+_)_\w*\.(\d{4})\.(\d\d)\.(\d\d)\.(\d\d)\./$tr{$1}_$2-$3-$4_$5-/; rename $_,$n or warn "rename $_,$n $!";
}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now