Results 1 to 7 of 7

Thread: Program to rename files

  1. #1
    Newbie
    Join Date
    Jun 2005
    Posts
    20

    Program to rename files

    I don't know much about programming but i need a program that renames all the files on a linux directory like this: whatever.mp3 to 001.mp3 or anything to 002.ogg. So i can send them to my dos mp3car without any problems. I know samba does that mangling thing but i need to rename the files on linux in order to make a playlist on my linux computer that is playable on the dos system.

    Thanks in advance!

  2. #2
    Low Bitrate
    Join Date
    Jul 2005
    Location
    Missouri
    Posts
    61

  3. #3
    pkg
    pkg is offline
    Low Bitrate pkg's Avatar
    Join Date
    Apr 2005
    Location
    Arizona
    Posts
    96
    I have been looking into something similar but don't have to worry about the 8.3 restriction and will be using ID3 tagging for music. Check out this project, it can rename and retag mp3s based upon the music signature. http://musicbrainz.org
    -pkg

    Check out my tC: http://publicjestering.com/tc
    Check out my site: http://publicjestering.com

  4. #4
    Maximum Bitrate kbyrd's Avatar
    Join Date
    Nov 2003
    Location
    Northern Arizona
    Posts
    485
    Here's a bash shell script that will do the trick. It's quick and dirty. It doesn't do any error checking, if your files are named songsdasdasd.foobar, it won't truncate the extension to 3 characters. It will make sure not to write a filename bigger than 8 digits though.

    I take no responsibility for this script. If it sets your puppy on fire and makes your child cry, that's your business.
    Code:
    ----- Beginning of script, don't include this line ------
    #!/bin/bash
    i=1;
    for file in *
    do
       ext=${file##*.}
       if [ "$file" != "$i.$ext" ]; then
          echo "moving $file to $i.$ext"
          mv $file $i.$ext
       else
          echo "skipping $file, already renamed."
       fi
       let i+=1
       if [ "$i" -gt "99999999" ]; then
          echo "too many files to fit in 8.3 naming scheme"
          break;
       fi
    done
    ----- End of script, don't include this line ------
    My worklog.
    Status: VM GTI sold, got out of the CarPC tinkering hobby, but I still think about getting back in.

  5. #5
    Variable Bitrate intuitionsys's Avatar
    Join Date
    Jul 2005
    Location
    Northern Virginia
    Posts
    293
    Interesting you're taking that approach. That's how my custom software imports files into it's permanent library, although I have no concern with DOS (when it imports it renames files as xxxxxx.mp3 and keeps track of where it left off for the next import).

    You can use the find command like this to create a readable text file you can then iterate through to rename your files:

    Code:
    find /source/of/mp3/files -name '*.mp3' -follow > /temp/text/file
    You can then use a simple for loop to iterate it as such:

    Code:
    COUNTER=0
    for MP3FILE in `cat /temp/text/file` ;
    do
        mv MP3FILE /destination/path/$COUNTER.mp3
        COUNTER=$((COUNTER++))
    done
    rm /temp/text/file
    I didn't test this but you get the idea. Hope that helps.

  6. #6
    Maximum Bitrate kbyrd's Avatar
    Join Date
    Nov 2003
    Location
    Northern Arizona
    Posts
    485
    Quote Originally Posted by intuitionsys
    Interesting you're taking that approach. That's how my custom software imports files into it's permanent library,
    Huh, did I come up with almost the exact code? I didn't plan it out or anything, I'm sure there are better ways to solve the problem. I just started typing, tested it once and posted the code.
    My worklog.
    Status: VM GTI sold, got out of the CarPC tinkering hobby, but I still think about getting back in.

  7. #7
    Variable Bitrate intuitionsys's Avatar
    Join Date
    Jul 2005
    Location
    Northern Virginia
    Posts
    293
    You did more than me I mainly posted the snippet re "find" as it will find files recursively if that's of any use.

Similar Threads

  1. CF 2.0: Language & Keyboard files
    By SOS in forum Centrafuse
    Replies: 35
    Last Post: 04-13-2007, 12:01 AM
  2. Does frodo support SHN files?
    By ayclens in forum FrodoPlayer
    Replies: 2
    Last Post: 11-07-2004, 06:15 PM
  3. Replies: 5
    Last Post: 08-17-2004, 12:08 PM
  4. Destinator 2 program files
    By zummi in forum GPS
    Replies: 0
    Last Post: 07-28-2004, 06:46 PM
  5. Renaming .wma files with FreeDB
    By meddler in forum General MP3Car Discussion
    Replies: 3
    Last Post: 07-20-2004, 06:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •