http://www.perlmonks.org?node_id=107193

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I rename a file to include the directory as part of the filename?

I have thousands of Bruce Springsteen MP3's on my PC. They are all from different live shows. They are setup in directories named for each show. However, the file names themselves do not have the artist or the concert as part of the file name.

For example, in the folder

/music/Springsteen/Springsteen - 1973-03-07 Max's Kansas City

I have several songs,

01 Mary Queen of Arkansas.mp3
02 Bishop Dance.mp3
...
...
08 Song to Orphans.mp3

Unfortunately the MP3 player I'm using only displays the file name in its playlist. Therefore identifying a particular song from a particular show is difficult. How can I rename the files to include the parent directory as part of the file name? I'm looking for a simple script that will let me do it.

Ideally my files would all be renamed like this :

Springsteen - 1973-03-07 Max's Kansas City - 01 Mary Queen of Arkansas.mp3
Springsteen - 1973-03-07 Max's Kansas City - 02 Bishop Dance.mp3
...
...
Springsteen - 1973-03-07 Max's Kansas City - 08 Song to Orphans.mp3

Can this be done?