Page 1 of 1

Using PascalScript to Append Subfolder to Filenames

Posted: Fri Nov 21, 2025 10:41 pm
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

Re: Using PascalScript to Append Subfolder to Filenames

Posted: Sat Nov 22, 2025 1:03 am
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;

Re: Using PascalScript to Append Subfolder to Filenames

Posted: Mon Nov 24, 2025 5:55 pm
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.

Re: Using PascalScript to Append Subfolder to Filenames

Posted: Mon Nov 24, 2025 8:02 pm
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!

Re: Using PascalScript to Append Subfolder to Filenames

Posted: Mon Nov 24, 2025 11:38 pm
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;