> I have a directory of files that I want to move to another directory.
> (eg. ALLY20030111W.eps
>      TEST W20030122
>      HELP WANTED20030901WW.eps
>      GIRL WATCH BIRD 20030101
> etc..)
> 
> I want to be able to parse the filename and replace the date portion with
> any date
> (eg $1="ALLY" $2="20030111" $3="W" $4=".eps")
> Then I want to make $2="20030925" and if $3 is empty then I assign ".eps"
> to $3 or if $4 is empty then assign ".eps"
> 
> 
> How do I do this?
> 
> #!/usr/bin/perl
> # move_file.plx
> use warnings;
> use strict;
> 
> $source = "/path/to/source/";
> $destination = "/path/to/destination/";
> $query = "([A-Za-z]+)(\s*?)([0-9]*)(\s*?)([A-Za-z]*)([eps])"
> opendir DH, $source or die "Couldn't open the current directory: $source";
> while ($_ = readdir(DH)) {
>    next if $_ eq "." or $_ eq "..";
> 
>    if (/$query/) {
>       print "Copying $_ ...\n";
>       rename $source$_, $destination$_;
>       print "file copied successfully.\n";
>    }
> }
> 
> What's wrong with my code. Am I overlooking something?
> 
> 

Reply via email to