Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp Help

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Joined
Dec 16, 2003
Messages
135
Could someone please tell me how to rename this file.

I have a filename which is fed as input to a program.
Input File = test_in_file_ddmmyyyy.lis.

I want to match this expression and if found true want
to rename the file to
TEST_FILE.lis.

Many Thanks in advance.
 
How about something like this:
Code:
print "Enter file name: ";
chomp(my $input = <STDIN>);
if ($input =~ /^test_in_file_\d{8}\.lis$/) {
    if (-e $input) {
        rename($input, 'TEST_FILE.lis') or
            die "Could not rename file.\n$!\n";
    } else {
        print "Cannot find file\n";
    }
} else {
    print "Invalid File Name\n";
}
 
Code:
$filename = "test_in_file_11042006.lis" ;

$filename =~ s/^test_in_file_[0-9]{8}.lis$/TEST_FILE.lis/  ;

#print $filename ;

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top