You are not logged in.
You're right, you weren't far off. *^^*
I just now noticed your note about "Length(FileNameTestWord) > 4", where you're checking that there is a real filename before you try to rename it. This does have some problems, however.... it assumes that the extension is always 3 characters long, which isn't necessarily true.
A better way to do this test would be "WideLength(WideExtractBaseName(FileNameTestWord)) > 0". It makes the constant a 0 (which is not as strange as 4 in program code), and addresses the issue of file extension length.
Offline
Hi prologician,
I've updated from your last post, fix the ReplaceRegEx arguments were wrong and add some comments.
Seems that is working
{File delete parent n grand parent folder string}
var
Path: TStringsArray;
Depth: Integer;
FileNameTest: WideString;
FileNameTestWord: WideString;
begin
if WideFileExists(FilePath) then {Process files only}
begin
Path:=WideSplitString(FilePath,'\'); {Create Array}
Depth:=Length(Path);
If (Depth>2) then {Check Parent and Grand Parent exist in Array}
begin
FileNameTest := WideReplaceStr(Path[Depth-1], Path[Depth-2], ''); {Replace Parent (If Found)}
FileNameTest := WideReplaceStr(FileNameTest, Path[Depth-3], ''); {Replace Grand-Parent (If Found)}
FileNameTestWord := ReplaceRegEx(FileNameTest, '(-_=|\s)' , '', False, False) {RegEx to clean up a testword}
If WideLength(WideExtractBaseName(FileNameTestWord)) > 0 then {Rename only if there is something left after replacing on the testword}
FileName := FileNameTest
end
end;
end.
Offline
Hi,
I'm really struggling with something which seems very related to this but since I don't understand pascal I don't know how to modify this script for my needs.
Basically, I have songs files in a big folder in the format "Artist - Song.mp3". I want to rename them so that all the songs by the same artist appear in separate folders. ie I want to have "Artist/Song.mp3".
Please can you help. I know this must be simple but I've been searching the forum for ages and still have no idea.
Thanks!
Offline
Use the latest beta, and use the Rearrange rule in it. (No scripts required at all).
Use the following settings:
Delimiter: " - " (without the quotes).
New pattern: $1\$2
Skip extension [x] (ticked)
See help here: http://www.den4b.com/wiki/ReNamer:Rules:Rearrange
(See example-2 in Advanced Uses section, halfway down the page, )
Last edited by narayan (2009-09-17 03:24)
Offline