Its been awhile since I've messed with any kind of programming and I'll admit, I'm a bit rusty. I am an avid amazon mp3 user, but their downloads always have extra stuff attached to the track name, like Explicit, or Album Version. I want to make a program that will ask for a number of characters to remove from the end of the file name, and then rename the file. Only part of this I have figured out is i need th os module to specify where the files are.

You can use the os module to change the names as well.
Assuming Windows:

os.system("rename longsongname.mp3 songname.mp3")

or

os.rename("longsongname.mp3","songname.mp3")

To shorten the names, you'll need slicing.

longName = "Thisisalongname.mp3"
shortName = longName.split(".")[0][:5]+".mp3"

output

>>> shortName
'Thisi.mp3'

How would I get a list of all the files in a folder and then looping though it?

Im pleased to announce I got this working, it changed the file names perfectly. trouble is the way Windows has my mp3s set up, they have a title too. And while the program did change the file names, the title stayed the same :/

import os

location = os.getcwd()
files = os.listdir(location)

textToRemove = " "+raw_input("Text to remove? ")

for i in files:
    oldFileName = i
    newFileName = oldFileName.replace(textToRemove,"")
    os.rename(oldFileName, newFileName)

And then I just move the program to the folder I want to change and run it from there.

At least this mutagen module installed easyly with it's setup file:

Mutagen works on Python 2.3+ and has no dependencies outside the
CPython standard library.

Installing
----------
$ ./setup.py build
$ su -c "./setup.py install"

from mutagen.id3 import ID3
id3info= ID3('08-AudioTrack 08.mp3')
for i in id3info:
    print i, id3info[i]

http://code.google.com/p/mutagen/

At least this mutagen module installed easyly with it's setup file:

from mutagen.id3 import ID3
id3info= ID3('08-AudioTrack 08.mp3')
for i in id3info:
    print i, id3info[i]

http://code.google.com/p/mutagen/

How would I install that within Windows though? All of the files on the code page are tar.gz and I have no idea how to install in windows.
I have Ubuntu on a laptop. I wouldn't be able to write the program in Ubuntu and run it in Windows would I, since I cant install the tar in Windows?

I quoted the installation part from readme. The setup worked perfectly for me in windows Xp. By the way this is standard way to install software written in python. Where you got error?

I quoted the installation part from readme. The setup worked perfectly for me in windows Xp. By the way this is standard way to install software written in python. Where you got error?

Sorry, I was just unfamilar with installing tar files in windows.
I ran the su -c command and it says su is an unrecognized command.

Well, I got the package installed and am trying to mess with it. So far I'm not having too much luck. I tried to use the sample code you gave me, and I keep getting a KeyError.

All right, so far my luck has been varied. i wrote a sample program that successfully changed the title of a single file. But when I changed my original program to use this, it deleted all of the ID3 info and then exited with an error.

Traceback (most recent call last):
  File "C:\Users\Jeff J Peterson\Desktop\Get Behind Me Satan\tester.py", line 11, in <module>
    audio = MP3(i, ID3 = EasyID3)
  File "C:\Python26\lib\site-packages\mutagen\__init__.py", line 75, in __init__
    self.load(filename, *args, **kwargs)
  File "C:\Python26\lib\site-packages\mutagen\id3.py", line 1990, in load
    self.info = self._Info(fileobj, offset)
  File "C:\Python26\lib\site-packages\mutagen\mp3.py", line 103, in __init__
    self.__try(fileobj, offset, size - offset, False)
  File "C:\Python26\lib\site-packages\mutagen\mp3.py", line 140, in __try
    raise HeaderNotFoundError("can't sync to an MPEG frame")
HeaderNotFoundError: can't sync to an MPEG frame
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.