I am trying to write a program that will rename files to an organizational standard. For example, MP3s will be renamed to "track number" SPACE "track title." My approach to this problem is that I would copy every single byte of information in the file and then put them into the new, correctly named file. I will delete the original and implement a way to rename multiple files later on in development. Anyway, here's the code:
The issue here is that I am not copying every byte and I think it's because the eof marking may appear at random times during the MP3 file. So then I tried some little snippet of code I found here on c++.com:
This produces gobbledygook that looks like the ID3 tags and then a repeated character when output to a text file. So my question is how do I rename a file in this fashion? Is there an easier way? I may be way over complicating things lol. I would like to stay away from using
string oldn;
string newn;
oldn = "C:\\Documents\\Programming\\Files\\07-luciano_pavarotti--miserere-_with_zucchero.mp3";
newn = "C:\\Documents\\Programming\\Files\\07 Miserere.mp3";
char *cstr1, *cstr2; //declaration of character string eventually pointing to the location where oldn and newn are stored
cstr1 = newchar [oldn.size()+1]; //allocate memory to hold oldn and newn PLUS the null terminated character
strcpy(cstr1, oldn.c_str()); //copy to cstr1 the contents of oldn. Note oldn.c_str() is the same as oldn only c_str points to a null terminated character array.
cstr2 = newchar [newn.size()+1];
strcpy(cstr2, newn.c_str());
cout << cstr1 << endl << endl; //checking to see what cstr1 and 2 hold
cout << cstr2 << endl << endl;
rename(cstr1, cstr2); //renaming
delete []cstr1;
delete []cstr2;
It would still be interesting to see what the bits were in the MP3 but in terms of renaming things, its solved.
char *cstr1, *cstr2; //declaration of character string eventually pointing to the location where oldn and newn are stored
cstr1 = newchar [oldn.size()+1]; //allocate memory to hold oldn and newn PLUS the null terminated character
strcpy(cstr1, oldn.c_str()); //copy to cstr1 the contents of oldn. Note oldn.c_str() is the same as oldn only c_str points to a null terminated character array.
cstr2 = newchar [newn.size()+1];
strcpy(cstr2, newn.c_str());
cout << cstr1 << endl << endl; //checking to see what cstr1 and 2 hold
cout << cstr2 << endl << endl;
rename(cstr1, cstr2); //renaming
delete []cstr1;
delete []cstr2;