You are not logged in.
Pages: 1
Hi, I love this program. I wrote my first script. I am sharing it, so others can use it. It's probably not very efficient right now, but i'll learn.
What it does:
- It renames all music files in a directory through the .m3u file.
How to make it work:
1. Create a directory and put your files in them (mp3, wav, etc). For the moment it's only important the files start with a tracknumber (e.g. 3 BLA.mp3, otherwise sorting is difficult).
2. Create a m3u file with the EXACT name of the directory it's in (e.g. if you music-files are in c:\Madonna\, then the m3u file must be named Madonna.m3u and placed in c:\Madonna\.
3. Put the wanted filenames in the m3u file. The name may be anything with legal characters.
4. Import files and run script.
// Read m3u file and rename files accordingly //
var
I: Integer;
Position: Integer;
FileNameLength: Integer;
PathNameLength: Integer;
PathName: string;
FolderName: string;
UserInput: WideString;
NewFileName: string;
TrackNumber: string;
FileExt: string;
begin
FileNameLength := Length(FileName);
PathNameLength := Length(FilePath);
PathName := FilePath;
NewFileName:= FileName;
for I := FileNameLength downto 1 do
begin
if (FileName[i] = '.') then
begin
Position := I;
break;
end;
end;
Delete(NewFileName, Position, FileNameLength);
for I := PathNameLength downto 1 do
begin
if (FilePath[i] = '\') then
begin
Position := I;
break;
end;
end;
Delete(PathName, Position ,PathNameLength);
for I := Length(PathName) downto 1 do
begin
if (FilePath[i] = '\') then
begin
Position := I;
break;
end;
end;
FolderName:= PathName;
Delete(FolderName, 1, Position);
PathName := PathName + '\';
Position := 1;
if (WideFileExists(PathName+FolderName+'.m3u')) then
begin
for I := 1 to Length(NewFileName) do
begin
if (IsWideCharDigit(FileName[i])) then
begin
Position := I;
end
Else
break;
end;
if Not (Position = 1) then
begin
TrackNumber := FileName;
Delete(TrackNumber, Position+1, FileNameLength);
UserInput := FileReadLine(PathName+FolderName+'.m3u', StrToInt(TrackNumber));
Position := 1;
for I := Length(UserInput) downto 1 do
begin
if (UserInput[i] = '.') then
begin
Position := I;
break;
end;
end;
if Not (Position = 1) then
begin
FileExt := UserInput;
Delete(FileExt, 1, Position-1);
if Not (WideExtractFileExt(FilePath) = FileExt) then
ShowMessage('FileExtention ('+WideExtractFileExt(FilePath)+') does not match m3u playlist ('+FileExt+')')
Else
FileName := UserInput;
end
Else
ShowMessage('Filename "'+UserInput+'" (Line '+IntToStr(StrToInt(TrackNumber))+') has no extention!');
end
Else
ShowMessage(Filename+'does not start with a number!');
end
Else
ShowMessage(PathName+FolderName+'.m3u does not exist!');
end.
update January 10, 2008:
- previous script did not work without my other rules (i didn't include)
- ignore leading zero's
- added some checks for validation
Last edited by ronnie_t (2008-01-10 01:03)
Offline
Thank you for sharing, ronnie_t
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
That does look like a big script, good man ronnie
Offline
Pages: 1