Hi there,
Im writing a program that reads ID3 tag information of songs in a given directory and then creates corresponding folders for that Song. (Ie the folder is called the ID3 artist's name). The song is then renamed and placed into the new folder.
However, i have come across both an anoying and totally mind bogoling problem which i just cant get my head around. I am trying to take a Directory (such as 'C:\Music\MP3') as one string in a variable ('RootDirectory'), a backslash and finally, another string (such as'Some Artist - Some Title.mp3') as another string variable('SourceFiles_Memo.Lines.Strings[Current]'), and then combine the two strings to get something like this:
'C:\Music\MP3\SomeArtist - Some Title.mp3'
However, what i am actually getting is this:
'\Some Artist - Some Title.mp3'
Now, the obvious thing here would be that the 'RootDirectory' string has nothing in it, but heres where it gets interesting. The 'RootDirectory' varable DOES have a string within it, and the 'SourceFiles_Memo.Lines.Strings[Current]' variable also has a string in it.
The Code for this procedure is shown below:
Procedure TFolderCreator_Form.Create_ButtonClick(Sender: TObject);
var
Current: integer;
OldFilename, NewFilename: String;
begin
//Check that files have been found
if SourceFiles_Memo.Lines.Count > 0 then
begin
//Run through each file that has been found in a loop
For Current := 0 to SourceFiles_Memo.Lines.Count do
begin
//Get The current Song filename
OldFilename := SourceDirectory + '\' + SourceFiles_Memo.Lines.Strings[Current];
Test1.Text := OldFilename;
//Get the ID3 tag information for song
Main_Form.GetID3(OldFilename);
//Rename the old file with new information
NewFilename := UMain_unit.ID3Artist + ' - ' + UMain_Unit.ID3Title;
Test3.Text := NewFilename;
//Create new folder for song
NewDirectory := SourceDirectory + '\' + ID3Artist;
Test2.Text := SourceDirectory;
Test4.Text := NewDirectory;
//Check if new folder exists, if not create it
if DirectoryExists(NewDirectory) then
begin
MoveFile(PChar(OldFilename), PChar(NewFilename));
end
else
begin
CreateDir(NewDirectory);
MoveFile(PChar(OldFilename), PChar(NewFilename));
end;
end;
SourceFiles_Memo.Lines.Clear;
end
else
ShowMessage('No files were found');
end;
Each 'TestN.text' edit box has been used to display the variables for troubleshooting only.
I have also tried using the 'Concat(String1,... ,StringN)' procedure, but i got exactly the same result.
Thank you in advance for any help anyone may be able to give,
Carson