Author Topic: Renaming an MP3 file using TrackNumber  (Read 1858 times)

barmst02

  • Newbie
  • *
  • Posts: 2
Renaming an MP3 file using TrackNumber
« on: July 05, 2012, 11:25:51 AM »
I'd like to include the Track Number in the filename for my MP3's, but many of them include the optional "/<position in set>" E.g.  1/13
4.2.1   TRCK    [#TRCK Track number/Position in set]

Not only is this not what I want, it results in very strange directory trees and filenames in Windows! Is there a way to extract just the Track (e.g. 1)?

Example command:
exiftool.exe -r "-Filename<$Artist.$Album.$Track.$Title.%e"
Note: I can't use underscores so I changed them to periods: Warning: [minor] Tag 'Artist_' not defined


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Renaming an MP3 file using TrackNumber
« Reply #1 on: July 05, 2012, 12:27:15 PM »
You can create a user-defined tag to do any conversions that you want.  See this post for a similar example.

It sounds like you want a conversion something like this:

ValueConv => '$val=~/(\d+)/; $1',

which will extract only the first integer number from the string.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

barmst02

  • Newbie
  • *
  • Posts: 2
Re: Renaming an MP3 file using TrackNumber
« Reply #2 on: July 05, 2012, 04:40:41 PM »
That was very helpful. Here is my config:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        OnlyTrack => {
            Require => 'Track',
            # only get first integer
       ValueConv => '$val=~/(\d+)/; $1',
       # an optional PrintConv may be used to format the value
            PrintConv => 'sprintf("%02s", $val)',
        },
    },
);
1;  #end