#1 2015-11-07 01:16

Ammar
Member
Registered: 2015-11-06
Posts: 6

Pascal Script: WideScanDirForFiles

Hi

i wrote a Pascal Script to change the the .jpg files name to match .mp4 file


From:
Toxin (2014) 1080p.BluRay.mp4
Toxin (2014) 1080p.jpg

Transformers Age of Extinction (2014) [3D] 1080p.BluRay.mp4
Transformers Age of Extinction (2014) [3D].jpg

Unfriended (2014) 1080p.BluRay.mp4
Unfriended (2014) 1080p.jpg


To:
Toxin (2014) 1080p.BluRay.mp4
Toxin (2014) 1080p.BluRay.jpg

Transformers Age of Extinction (2014) [3D] 1080p.BluRay.mp4
Transformers Age of Extinction (2014) [3D] 1080p.BluRay.jpg

Unfriended (2014) 1080p.BluRay.mp4
Unfriended (2014) 1080p.BluRay.jpg


In case of Transformers Age of Extinction (2014) [3D] the function WideScanDirForFiles reports 0 file found

can you please help
Also like the script to work for .mkv & .avi files too


Pascal Script:

var  Parts, Files : TStringsArray;
     Ext, Path, Mask  : WideString;
begin

  Ext   := WideExtractFileExt(FilePath);
  if Not WideSameText( Ext, '.jpg') then Exit;

  If WidePos( '[3D]', FileName) > 0 then
     Parts := SubMatchesRegEx(FileName, '(.+])', False)  
  Else  
      Parts := SubMatchesRegEx(FileName, '(.+\))', False);

  Mask  := Parts[0] + '*.mp4';
  Path  := WideExtractFilePath(FilePath);
  SetLength(Files, 0 );
  WideScanDirForFiles( Path, Files, False, False, False, Mask );

  ShowMessage( 'Files Found :=  ' + IntToStr(length(Files))  );

  if (length(Files)>0) then
      begin
        ShowMessage( 'New File Name :=  ' + WideExtractBaseName(Files[0]) );
        FileName := Path + WideExtractBaseName(Files[0]) + Ext;
      end;
end.

Offline

#2 2015-11-07 18:16

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

Re: Pascal Script: WideScanDirForFiles

There are 2 problems in your script:

  1. You need to escape meta characters in RegEx expressions: "(.+])" should be "(.+\])"

  2. You are passing a portion of file name as a wildcard mask, which can have meta wildcard characters which get interpreted differently.

Transformers Age of Extinction (2014) [3D]*.mp4

Square brackets have a special meaning in wildcard masks, it matches a single character from the specified range, so "[3D]" mask will not actually match literal "[3D]".

To work around this problem, you can find the matching file manually. Scan for all *.mp4 files and enumerate them all to find the one that starts with your desired partial file name.

Offline

Board footer

Powered by FluxBB