in reply to Re^3: Removing characters in a file name
in thread Removing characters in a file name

Thanks for the reply. It's working now. Unfortunately I found out that I have some files that have the following format too

JohnDoe-JaneDoe-399-1080p.mp4

So the only common thing of this new file format with the previous format is the number between the two dashes. There could be spaces before or after the two dashes too. So the two formats that I have will be below

JohnDoe-JaneDoe-399-1080p.mp4 John Doe & Jane Doe - 458 - Bonds.mp4

As you can see, there could be spaces before and after the dashes so the only consistent thing between the two file naming formats is there will be a number between two dashes

Is there a way to modify the if statement to accommodate both file formats?

Replies are listed 'Best First'.
Re^5: Removing characters in a file name
by jwkrahn (Abbot) on Apr 23, 2020 at 03:11 UTC
    for my $file ( <*.mp4> ) { if ( $file =~ /-\s*(\d+)\s*-/ ) { rename $file, "[Books] $1.mp4" or die "Cannot rename '$file' b +ecause: $!"; } }

      Thanks a lot. It's working now