Renaming a Number of Files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming a Number of Files
# 1  
Old 06-12-2008
Renaming a Number of Files

I want to rename my mp3s. Iw ant them to use a standard of 'Band Name - Song Title.mp3'. Currently, all of my mp3s are in the following directory structure:

/MyMusic/Band Name/Album Name/*.mp3


Esentailly I want to update each file with the Band Name from the hierarchy and then move all files to the /MyMusic dir. Also, I want to delete the Band Name and Album Name dirs after all files have been moved out.

Thanks in advance!
# 2  
Old 06-12-2008
I know you're looking for a cool unixy way to change your music files, but...

In my other life, I'm a mobile DJ, specializing in weddings. DJ Teddy Bear & Reverend Dave - Your Wedding Done Your Way.

When questions like this come up on the various DJ message boards, the answer is usually the same:

You're best off letting the software you used to rip your CDs, name and store the MP3s where and how it wants. Put too many MP3s in a single directory and the software may choke. Also, most software has the ability to open and show you the folder containing any song, so you really don't need to be able to find stuff on your own.
# 3  
Old 06-12-2008
You might want to write a shell script. First get the list of bands then loop for each band by listing their album name and then loop for each song.

This might not be accurate but you might be able to get it to work,

Code:
mpath="/MyMusic"
for band in `ls -p $mpath | grep "/$" | cut -d"/" -f1`
do
  bandpath="$mpath/$band"
  for album in `ls -p $bandpath | grep "/$" | cut -d"/" -f1`
  do
     albumpath="$bandpath/$album"
     cd $albumpath
     fl_lst=`ls *.mp3`
     cd - > /dev/null
     for fl in $fl_lst
     do
        cp $mpath/$band/$album/$fl $mpath/$band-$album-$fl
     done
  done
done

I am using cp instead of mv so that you can test it out. you if you think it works, just change 'cp' to 'mv'

-kj

Last edited by Yogesh Sawant; 06-13-2008 at 02:15 AM.. Reason: added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming a file with sequence number

Hi team, I need a script for renaming a file with sequence number. script get a file from one directory, /home/billing/Cmm/sms/sms_tmp, append sequence no at the end of file name and move a file to other directory, /home/billing/Cmm/sms/. Actual file is cdr201508271527, and file after... (10 Replies)
Discussion started by: mfaizan40
10 Replies

2. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

3. Shell Programming and Scripting

Renaming the file name for n number of files

Hi , I am kind of new to shell scripting and found a situation to handle ... I have few files which will be ftpd in to our sustem , the file names needs to be renamed based on condition. ------------ Eg file names :- AE_JUNFOR_2013_MTD_2013-04-09-08-30-09.TXT... (6 Replies)
Discussion started by: chillblue
6 Replies

4. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

5. UNIX for Dummies Questions & Answers

Renaming Files With 2 .

Dear All expertise.. just wanna ask if there is a way on how to change the filename as per below sample:- filename:- cob120514093156.03.466926330 CCBS-CPMM_SEND_COB_120514_100549_3.rpt to convert to:- cob120514093156.03.466926330.bd (rename from cob120514093156.03.466926330) ... (17 Replies)
Discussion started by: yokomo
17 Replies

6. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

7. UNIX for Advanced & Expert Users

Renaming files

Hello Please can someone help. We are being sent a directiory full of images. The names of these images can vary in length and have spaces in them. example: nn 999999 nnnnn nnnn nnnn nn nnn nnn nn nnnn.pdf what we want to do is rename all the images. Take the first two fields nn 999999 and... (23 Replies)
Discussion started by: Dolph
23 Replies

8. Shell Programming and Scripting

renaming and number padding using directory as guide, help

I need to take a series of image files, all numbered consecuativly, that were recently dumped in a directory and rename them to pieces of the directories path. Assume all directories are structured as this one so that I may use this script to easly sort and rename files. pt.1 path :... (3 Replies)
Discussion started by: TiredOrangeCat
3 Replies

9. UNIX for Dummies Questions & Answers

renaming files

directory name = /usr/tom/1997 files - ABC_1997_ST1_BCD.SQL BCD_1997_ST1_EFG_SAB.SQL TTT_EBC_1997_ST1_A.SQL sub directory - /usr/tom/1997/jan a) I want to just rename the all files ending with '.SQL' and also its contents in the 1997 directory(excluding subdirectories eg... (3 Replies)
Discussion started by: systemsb
3 Replies

10. UNIX for Dummies Questions & Answers

renaming the files

Hi All, Today I got a small problem while handling zipped files in PROD support. There are files in this format and I had to grep them reading some contents A.B.gz.C.D where A,B,C and D stand for variables (like FIRST.NAME.gz.MIDDLE.LAST). I know that these files are zipped files and If I... (1 Reply)
Discussion started by: adurga
1 Replies
Login or Register to Ask a Question