You are not logged in.
Pages: 1
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
There are 2 problems in your script:
You need to escape meta characters in RegEx expressions: "(.+])" should be "(.+\])"
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]*.mp4Square 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
Pages: 1