Script started on Fri May 2 03:30:00 2003 [root@Fizzgig /root]# cd C [root@Fizzgig C]# cat makefile renamemp3: main.o g++ -g main.o -o renamemp3 main.o: main.cpp g++ -c main.cpp [root@Fizzgig C]# cat main.cpp /* A program that helps rename mp3 files by processing their */ /* filenames to meet ISO-9660. */ /* Given a file or pipe of directory contents, this program */ /* produces a list of MSDOS rename commands to fix those files. */ /* Author: Zach Tomaszewski */ /* Date: 01 May 2003 */ #include #include #include void usage(); string replaceall(string s, string search, string replace); int main(int argc, char* argv[]) { string filename; string line; //get filename if (argc == 2) { filename = argv[1]; }else if (argc == 1){ cout << "Enter filename: "; cin >> filename; }else { usage(); return(0); } //open file ifstream fileIn(filename.c_str()); if (!fileIn){ cout << "Could not open input file: " << filename << endl; return(1); } //process lines string oldname; string newname; int pos; while(!fileIn.eof()){ getline(fileIn, line); if (line.find(".mp3", 0) != string::npos) { //work with files only line = replaceall(line, "\r", ""); newname = oldname = line.substr(39); //grab only filenames newname = replaceall(newname, ".mp3", ""); //drop ".mp3" newname = replaceall(newname, "'", ""); //drop "'"s newname = replaceall(newname, " & ", "-"); //turn " & " into - newname = replaceall(newname, "&", "-"); //turn "&" into - while(newname.length() > 26) { //remove full words to get length int space = newname.find_last_of(" "); int end = newname.length(); newname.replace(space, end, ""); } newname = replaceall(newname, " ", "_"); //turn " " into _ newname += ".mp3"; cout << "rename \"" << oldname << "\" " << newname << endl; } } return 0; } /* Prints a usage message to the screen */ void usage(){ cout << "\nUsage: renamemp3 [filename]\n\n"; cout << "\tIssues DOS rename commands for all mp3 files in "; cout << "the given file\n"; cout << "\tso that files will meet ISO-9660 specs.\n"; cout << endl; } /* Replaces all instances of "search" with "replace" found in s. */ string replaceall(string s, string search, string replace){ int pos; for(pos = 0; (pos = s.find(search)) != string::npos; s.replace(pos, search.length(), replace)){ } return s; } [root@Fizzgig C]# make g++ -c main.cpp g++ -g main.o -o renamemp3 [root@Fizzgig C]# renamemp3 dir.txt rename "1-1 Self Introduction.mp3" 1-1_Self_Introduction.mp3 rename "1-2 A&B Pronunciation.mp3" 1-2_A-B_Pronunciation.mp3 rename "1-2 C-E Pronunciation.mp3" 1-2_C-E_Pronunciation.mp3 rename "1-2 F-End Pronunciation.mp3" 1-2_F-End_Pronunciation.mp3 rename "1-3 Greetings.mp3" 1-3_Greetings.mp3 rename "1-4 Classroom Expressions.mp3" 1-4_Classroom_Expressions.mp3 rename "1-5 Numbers 1-10.mp3" 1-5_Numbers_1-10.mp3 rename "1-6 Numbers 11-100.mp3" 1-6_Numbers_11-100.mp3 rename "1-7 Weather Expressions.mp3" 1-7_Weather_Expressions.mp3 rename "1 Lab III.mp3" 1_Lab_III.mp3 rename "1 lab II.mp3" 1_lab_II.mp3 rename "1 Lab IV & V.mp3" 1_Lab_IV-V.mp3 rename "1 Lab I.mp3" 1_Lab_I.mp3 rename "1 Lab VI-VIII.mp3" 1_Lab_VI-VIII.mp3 rename "2-1 Classroom Japanese.mp3" 2-1_Classroom_Japanese.mp3 rename "2-2 Teacher's Directions.mp3" 2-2_Teachers_Directions.mp3 rename "2-3 What is This.mp3" 2-3_What_is_This.mp3 rename "2-4 This Book is Mine.mp3" 2-4_This_Book_is_Mine.mp3 rename "2-5 Please Give Me.mp3" 2-5_Please_Give_Me.mp3 rename "2 Lab III.mp3" 2_Lab_III.mp3 rename "2 Lab II.mp3" 2_Lab_II.mp3 rename "2 Lab IV.mp3" 2_Lab_IV.mp3 rename "2 Lab I.mp3" 2_Lab_I.mp3 rename "2 Lab V & VI.mp3" 2_Lab_V-VI.mp3 rename "Review 1&2.mp3" Review_1-2.mp3 rename "11-1 When Is Your Birthday.mp3" 11-1_When_Is_Your_Birthday.mp3 rename "11-2 I Have An Exam On The 10th.mp3" 11-2_I_Have_An_Exam_On_The.mp3 rename "11-3 My Teacher Is Strict.mp3" 11-3_My_Teacher_Is_Strict.mp3 rename "11-4 I Had A Good Grade.mp3" 11-4_I_Had_A_Good_Grade.mp3 rename "11-5 There Is A Lot Of Homework.mp3" 11-5_There_Is_A_Lot_Of.mp3 rename "11 lab III.mp3" 11_lab_III.mp3 rename "11 lab II.mp3" 11_lab_II.mp3 rename "11 Lab I.mp3" 11_Lab_I.mp3 rename "11 Lab IV.mp3" 11_Lab_IV.mp3 rename "11 lab V.mp3" 11_lab_V.mp3 rename "12-1 What Happened.mp3" 12-1_What_Happened.mp3 rename "12-2 I Want To Sleep.mp3" 12-2_I_Want_To_Sleep.mp3 rename "12-3 We Lost The Game.mp3" 12-3_We_Lost_The_Game.mp3 rename "12-4 Schedule.mp3" 12-4_Schedule.mp3 rename "12-5 Shall We Meet At My House.mp3" 12-5_Shall_We_Meet_At_My.mp3 rename "12 Lab III.mp3" 12_Lab_III.mp3 rename "12 Lab II.mp3" 12_Lab_II.mp3 rename "12 Lab I.mp3" 12_Lab_I.mp3 rename "12 Lab IV.mp3" 12_Lab_IV.mp3 rename "12 lab V.mp3" 12_lab_V.mp3 rename "Review 11 & 12.mp3" Review_11-12.mp3 rename "13-1 Verb Te Form.mp3" 13-1_Verb_Te_Form.mp3 rename "13-2 Please Show It To Me.mp3" 13-2_Please_Show_It_To_Me.mp3 rename "13-3 I Want To Buy A Black Or White Watch.mp3" 13-3_I_Want_To_Buy_A_Black.mp3 rename "13-4 How Much Is That Shirt.mp3" 13-4_How_Much_Is_That.mp3 rename "13-5 It Is Cheap.mp3" 13-5_It_Is_Cheap.mp3 rename "13 Lab I.mp3" 13_Lab_I.mp3 rename "13 Lab II.mp3" 13_Lab_II.mp3 rename "13 Lab III.mp3" 13_Lab_III.mp3 rename "13 Lab IV.mp3" 13_Lab_IV.mp3 rename "13 Rolling Musubi.mp3" 13_Rolling_Musubi.mp3 rename "14-1 I Am Hungry.mp3" 14-1_I_Am_Hungry.mp3 rename "14-2 Pizza Is $3 and Cola Is 75 Cents.mp3" 14-2_Pizza_Is_$3_and_Cola.mp3 rename "14-3 I Eat With Chopsticks.mp3" 14-3_I_Eat_With_Chopsticks.mp3 rename "14-4 It's Cheap And Delicious.mp3" 14-4_Its_Cheap_And.mp3 rename "14-5 I Go To The Library And Do My Homework.mp3" 14-5_I_Go_To_The_Library.mp3 rename "14 Lab I.mp3" 14_Lab_I.mp3 rename "14 Lab II.mp3" 14_Lab_II.mp3 rename "14 Lab III.mp3" 14_Lab_III.mp3 rename "14 Lab IV.mp3" 14_Lab_IV.mp3 rename "14 Lab V.mp3" 14_Lab_V.mp3 rename "14 Lab VI.mp3" 14_Lab_VI.mp3 rename "Review 13 & 14.mp3" Review_13-14.mp3 rename "15-1 Happy Birthday.mp3" 15-1_Happy_Birthday.mp3 rename "15-2 I Received Birthday Presents.mp3" 15-2_I_Received_Birthday.mp3 rename "15-3 I Give Flowers.mp3" 15-3_I_Give_Flowers.mp3 rename "15-4 Please Come To My Party.mp3" 15-4_Please_Come_To_My.mp3 rename "15-5 Say Cheese.mp3" 15-5_Say_Cheese.mp3 rename "15 Lab I.mp3" 15_Lab_I.mp3 rename "15 Lab II & III.mp3" 15_Lab_II-III.mp3 rename "15 Lab IV & V.mp3" 15_Lab_IV-V.mp3 rename "15 Lab VI.mp3" 15_Lab_VI.mp3 rename "15 Story.mp3" 15_Story.mp3 rename "Review 15.mp3" Review_15.mp3 rename "10-1 Jon Is Outdoors.mp3" 10-1_Jon_Is_Outdoors.mp3 rename "10-2 There Is A Pool Over There.mp3" 10-2_There_Is_A_Pool_Over.mp3 rename "10-3 There Are Many Flowers.mp3" 10-3_There_Are_Many.mp3 rename "10-4 The Office Is In That Building.mp3" 10-4_The_Office_Is_In_That.mp3 rename "10-5 My Room Is Small.mp3" 10-5_My_Room_Is_Small.mp3 rename "10 Lab I.mp3" 10_Lab_I.mp3 rename "10 Lab II.mp3" 10_Lab_II.mp3 rename "10 Lab III.mp3" 10_Lab_III.mp3 rename "10 Lab IV.mp3" 10_Lab_IV.mp3 rename "10 Lab V.mp3" 10_Lab_V.mp3 rename "9-1 Did You Go To A Movie Yesterday.mp3" 9-1_Did_You_Go_To_A_Movie.mp3 rename "9-2 Was The Movie Good.mp3" 9-2_Was_The_Movie_Good.mp3 rename "9-3 Did You Like It.mp3" 9-3_Did_You_Like_It.mp3 rename "9-4 Was That A Good Movie.mp3" 9-4_Was_That_A_Good_Movie.mp3 rename "Fun Corner 6 Tongue Twisters.mp3" Fun_Corner_6_Tongue.mp3 rename "Review 10.mp3" Review_10.mp3 rename "3-1 My Family.mp3" 3-1_My_Family.mp3 rename "3-2 Friend's Family.mp3" 3-2_Friends_Family.mp3 rename "3-3 Grade.mp3" 3-3_Grade.mp3 rename "3-4 Nationality.mp3" 3-4_Nationality.mp3 rename "3-5 Job.mp3" 3-5_Job.mp3 rename "3 Lab II.mp3" 3_Lab_II.mp3 rename "3 lab I.mp3" 3_lab_I.mp3 rename "4-1 What Language.mp3" 4-1_What_Language.mp3 rename "4-2 What Do You Eat.mp3" 4-2_What_Do_You_Eat.mp3 rename "4-3 What Did You Eat.mp3" 4-3_What_Did_You_Eat.mp3 rename "4-4 What Do You Do At School.mp3" 4-4_What_Do_You_Do_At.mp3 rename "4-5 What Do You Do At Home.mp3" 4-5_What_Do_You_Do_At_Home.mp3 rename "4 Lab A-D.mp3" 4_Lab_A-D.mp3 rename "4 Lab E-H.mp3" 4_Lab_E-H.mp3 rename "4 Lab I-M.mp3" 4_Lab_I-M.mp3 rename "Review 3 & 4.mp3" Review_3-4.mp3 rename "7-1 Let's Watch A Movie On Saturday.mp3" 7-1_Lets_Watch_A_Movie_On.mp3 rename "7-2 What Time.mp3" 7-2_What_Time.mp3 rename "7-3 What Time Do You Go Home.mp3" 7-3_What_Time_Do_You_Go.mp3 rename "7-4 I Come To School By Bus.mp3" 7-4_I_Come_To_School_By.mp3 rename "7-5 Saturday.mp3" 7-5_Saturday.mp3 rename "7 Lab A.mp3" 7_Lab_A.mp3 rename "7 Lab B.mp3" 7_Lab_B.mp3 rename "7 Lab C.mp3" 7_Lab_C.mp3 rename "7 lab D & E.mp3" 7_lab_D-E.mp3 rename "7 Lab F & G.mp3" 7_Lab_F-G.mp3 rename "Review 7.mp3" Review_7.mp3 rename "5-1 What Is Your Hobby.mp3" 5-1_What_Is_Your_Hobby.mp3 rename "5-2 What Do You Like.mp3" 5-2_What_Do_You_Like.mp3 rename "5-3 What Are You Good At.mp3" 5-3_What_Are_You_Good_At.mp3 rename "5-4 You Are Very Skillful.mp3" 5-4_You_Are_Very_Skillful.mp3 rename "5-5 What Color.mp3" 5-5_What_Color.mp3 rename "5 Lab A-D.mp3" 5_Lab_A-D.mp3 rename "5 Lab E-H.mp3" 5_Lab_E-H.mp3 rename "5 Lab I-L.mp3" 5_Lab_I-L.mp3 rename "6-1 He Is Tall.mp3" 6-1_He_Is_Tall.mp3 rename "6-2 She Is Smart.mp3" 6-2_She_Is_Smart.mp3 rename "6-3 My Eyes Are Brown.mp3" 6-3_My_Eyes_Are_Brown.mp3 rename "6-4 He Is Fat.mp3" 6-4_He_Is_Fat.mp3 rename "6-5 She Is Cute.mp3" 6-5_She_Is_Cute.mp3 rename "6 Lab A-D.mp3" 6_Lab_A-D.mp3 rename "6 Lab E-J.mp3" 6_Lab_E-J.mp3 rename "6 Lab K-N.mp3" 6_Lab_K-N.mp3 rename "Review 5 & 6.mp3" Review_5-6.mp3 [root@Fizzgig C]# exit Script done on Fri May 2 03:30:35 2003