mp3 file renamer

This is a discussion on mp3 file renamer within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have been looking around on the internet trying to find a program that will rename my mp3 ...

  1. #1
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115

    mp3 file renamer

    Hi all, I have been looking around on the internet trying to find a program that will rename my mp3 files to the details that are in their id3 tags. But before I go to pay for one I though I might have a go at making one my self… it sounds easy enough.

    Now before I have even started to do any coding I have hit a few brick walls and need some help.

    Like how do I read id3 tags? How do I even get the program to open the mp3 files in a folder with out knowing the names of them?

    Can someone give me a few pointers to get me started? Or direct me to some online resources?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    To learn the names of files, you can use FindFirstFile/FindNextFile on Win32, glob() or readdir() on POSIX, or Boost.Filesystem anywhere.

    To read their ID3 info, I strongly recommend using id3lib. The ID3 format is getting more and more insane, so writing your own parser is not a good idea.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    This is how you would look through the folder and rename them:
    Code:
    #include <iostream> 
    #include <fstream>
    #include <windows.h> 
    #include <direct.h>
    using namespace std;
    
    void DoSomethingWithMP3S(string fileName)
    {
        // Do something with MP3's
        cout << fileName << endl;
    }
    
    int main()
    {
        HANDLE hFind;
        WIN32_FIND_DATA FindData;
    
        hFind = FindFirstFile ("C:\\My Folder\\*.mp3", &FindData); // The *.mp3 tells it search for all files with the extension mp3
        DoSomethingWithMP3S(FindData.cFileName);
        while (FindNextFile(hFind, &FindData))
        {
            DoSomethingWithMP3S(FindData.cFileName);
        }
    }
    I agree with CornedBee about id3lib. I had a lot of trouble before getting it to work, so I'll try and help you:

    1. Go to downloads, download Windows binaries and id3lib. That's what you want.
    2. Next, put the extract the id3lib folder somewhere, and put the .lib and .dll files in the folder with your program.
    3. Include the folder \id3lib-3.8.3\include and \id3lib-3.8.3\include\id3 to your project.
    4. Add #include <id3/tag.h> to the top of your project.
    5. Lastly, link the id3lib.lib to your project, either through the settings or like this: #pragma comment(lib, "id3lib.lib")

    I think that's everything I did to make it work, I hope this helps because I spent hours trying to figure out how to do this.

  4. #4
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Sweet thanks, That should be enough to get me well on my way...

    Edit:

    Just tried to compile that code, and i get this error
    error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'const char [19]' to 'LPCWSTR'
    I have come across this before, but i cant remember what it was... :S
    Last edited by Loic; 10-16-2007 at 05:37 PM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  6. #6
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    You could do that, or just do it this way:
    Code:
    string filePath = "C:\\My Folder\\*.mp3";
    
    hFind = FindFirstFile ((filePath).c_str(), &FindData);
    That's what I actually had in my program but I thought that either way would work. I'm not entirely sure why this way works, but it did for me so there you go.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21