#1 2013-12-14 13:57

nichtsooft
Member
Registered: 2013-12-10
Posts: 2

My own little RenameScript

Hi there!
I haven't done Pascal since I was in sec. modern school, but I gave it a shot
--> It didn't work and that's why I end up here! sad

Basically it's about cleaning up folders containing audio -and associated other files...
I got a FolderStructure like "X:\genre\subgenre\band - album - year - format\filename" and if some filenames hit some criteria I'm tryn' to rename them as you can see in the script:

VAR
	Folders, Parts: TStringsArray;
	ThisFolderName, Band, Album, ThisFileName, NewFileName: WideString;
	PathDepth, FolderParts : Integer;

BEGIN
	Folders		:= WideSplitString(FilePath,'\');
	PathDepth	:= Length(Folders);
	IF PathDepth > 1 THEN
	BEGIN
		ThisFolderName	:= Folders[PathDepth-1];
		Parts			:= WideSplitString(ThisFolderName,' - ');
		FolderParts		:= Length(Parts);
		IF FolderParts > 1 THEN
		BEGIN
			Band		:= Parts[0];
			Album		:= Parts[1];
			ThisFileName:= WideExtractFileName(FilePath);
			IF WidePos('checker.log', ThisFileName) > 0 THEN
				FileName:= Band + Album + ' - Audiochecker.log';
			ELSE IF WidePos('LAC.log', ThisFileName) > 0 THEN
				FileName:= Band + Album + ' - LAC.log';
			ELSE IF WidePos('_r.jpg', ThisFileName) > 0 THEN
				FileName:= Band + Album + ' - Cover.jpg';
			ELSE IF WidePos('Artwork.jpg', ThisFileName) > 0 THEN
				FileName:= Band + Album + ' - Artwork.jpg';
			END;
		END;
	END;
END.

The problem is that I end up with an Error when I try to compile my script: Line 21: Error: Identifier expected

Could u please help me out with this one?

Last edited by nichtsooft (2013-12-14 14:00)


while (!$asleep) {$sheep++ }

Offline

#2 2013-12-14 16:31

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: My own little RenameScript

Hello, and welcome!

The "Identifier expected" error is caused by a slight syntax issue around the "ELSE IF" keywords.

The statement that precedes "ELSE" keyword must not have a terminating semicolon ";". Below are few examples:

  • IF condition THEN statement;

  • IF condition THEN statement ELSE statement;

  • IF condition THEN statement ELSE IF condition THEN statement;

  • IF condition THEN BEGIN statement; statement; END;

  • IF condition THEN BEGIN statement; statement; END ELSE statement;

In your script, this part...

IF WidePos('checker.log', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Audiochecker.log';
ELSE IF WidePos('LAC.log', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - LAC.log';
ELSE IF WidePos('_r.jpg', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Cover.jpg';
ELSE IF WidePos('Artwork.jpg', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Artwork.jpg';
END;

Need to be as follows...

IF WidePos('checker.log', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Audiochecker.log'
ELSE IF WidePos('LAC.log', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - LAC.log'
ELSE IF WidePos('_r.jpg', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Cover.jpg'
ELSE IF WidePos('Artwork.jpg', ThisFileName) > 0 THEN
	FileName:= Band + Album + ' - Artwork.jpg';

All I did was removed terminating semicolons ";" before "ELSE" and removed "END;" as it is not needed there.

Also, this resource might come in handy: http://www.den4b.com/wiki/ReNamer:Pascal_Script

Offline

#3 2013-12-14 17:54

nichtsooft
Member
Registered: 2013-12-10
Posts: 2

Re: My own little RenameScript

Aaaahhhh....
Cheers m8. That helped me a lot!
So here's the final script if anyone should need it in the future:

VAR
	Parts: TStringsArray;
	ThisFolderName, Band, Album, ThisFileName: WideString;
	FolderParts : Integer;

BEGIN
	ThisFolderName	:= WideExtractFileName(WideExtractFileDir(FilePath)); 
	Parts			:= WideSplitString(ThisFolderName,' - ');
	FolderParts		:= Length(Parts);
	IF FolderParts > 1 THEN
	BEGIN
		Band		:= Parts[0];
		Album		:= Parts[1];
		ThisFileName:= WideExtractFileName(FilePath);
		IF WidePos('audiochecker.log', ThisFileName) > 0 THEN
			FileName:= Band + ' - ' + Album + ' - Audiochecker.log'
		ELSE IF WidePos('LAC.log', ThisFileName) > 0 THEN
			FileName:= Band + ' - ' + Album + ' - LAC.log'
		ELSE IF WidePos('_r.jpg', ThisFileName) > 0 THEN
			FileName:= Band + ' - ' + Album + ' - Cover.jpg'
		ELSE IF WidePos('Artwork.jpg', ThisFileName) > 0 THEN
			FileName:= Band + ' - ' + Album + ' - Artwork.jpg'
		ELSE IF WidePos('Invoice', ThisFileName) > 0 THEN
			FileName:= Band + ' - ' + Album + ' - ' + ThisFileName;
	END;
END.

while (!$asleep) {$sheep++ }

Offline

Board footer

Powered by FluxBB