Using PascalScript to Append Subfolder to Filenames

General Discussion in English
Post Reply
mca27
Posts: 3
Joined: Fri Nov 21, 2025 10:02 pm

Using PascalScript to Append Subfolder to Filenames

Post by mca27 »

Hi all,

I am fairly new to Syncovery and have a question that I believe pertains to the Job-related settings > PascalScript prompt.

I would like to append the subfolder name to the files contained within them before moving from left to right. I first tried using a Filename inclusion mask but this did not seem to work. I'm now attempting to use PascalScript to accomplish this, specifically the OnReplaceFilenameLeftToRight function. I've copied the function sample script which appends '-draft' to the filename, but how would I go about making this a dynamic variable that points to the subfolder name?

Thank you in advance.

Marissa
tobias
Posts: 2094
Joined: Tue Mar 31, 2020 7:37 pm

Re: Using PascalScript to Append Subfolder to Filenames

Post by tobias »

For example:

Code: Select all

function OnReplaceFilenameLeftToRight(const FileName: UnicodeString;
        const isFolder: Boolean):UnicodeString;
begin
  if isFolder or (CurrentSubPath='') then
    Result:=FileName
  else
    Result:=FileName+StringReplace(CurrentSubPath,'\','_',false);
  end;
mca27
Posts: 3
Joined: Fri Nov 21, 2025 10:02 pm

Re: Using PascalScript to Append Subfolder to Filenames

Post by mca27 »

Thank you Tobias! Is there a way to alter the position of the '.xml' file extension within this script? When applying this script currently, it appends in the middle of the file name, so I am then unable to open the file.
mca27
Posts: 3
Joined: Fri Nov 21, 2025 10:02 pm

Re: Using PascalScript to Append Subfolder to Filenames

Post by mca27 »

Please disregard - I was able to modify the script so the file name now appears at the end of the statement. Thank you again!
tobias
Posts: 2094
Joined: Tue Mar 31, 2020 7:37 pm

Re: Using PascalScript to Append Subfolder to Filenames

Post by tobias »

Hello,
great.

Just for reference, the recommende way to do it is this:

Code: Select all

function OnReplaceFilenameLeftToRight(const FileName: UnicodeString;
        const isFolder: Boolean):UnicodeString;
begin
  if isFolder or (CurrentSubPath='') then
    Result:=FileName
  else
    Result:=ChangeFileExt(FileName,StringReplace(CurrentSubPath,'\','_',false)+ExtractFileExt(FileName));
  end;
Post Reply