Before posting, and to avoid disappointment, please read the following:

  • This forum is not for 2BrightSparks to provide technical support. It's primarily for users to help other users. Do not expect 2BrightSparks to answer any question posted to this forum.
  • If you find a bug in any of our software, please submit a support ticket. It does not matter if it is freeware or you haven't yet purchased the software. We want to know about any and all bugs so we can fix them as soon as possible. We usually need lots of information and details from you to reproduce bugs and that is better done via a support ticket and not this forum.

RunBeforeFolderCompare Does not skip requested Folders

For technical support visit http://support.2brightsparks.com/
Post Reply
taviso
Newbie
Newbie
Posts: 2
Joined: Tue May 14, 2019 1:25 pm

RunBeforeFolderCompare Does not skip requested Folders

Post by taviso » Tue May 14, 2019 1:33 pm

Hello, I am trying to skip folders that contain a specific file. I am using the RunBeforeFolderCompare hook, however no matter what I set the Skip variable to, the folder is never skipped. My simple script is below, the hook is called as I would expect, but setting Skip doesn't do anything. Even this minimal case doesn't seem to change the result:

Code: Select all

Procedure RunBeforeFolderCompare(Foldername; var Skip);
begin
    Skip := True;
end
There are no examples using this hook, am I using it correctly?

Thank you for your help.

Code: Select all

//
// Ignore all files containing a flag file.
// SBLang=Pascal
//

Function Description(var ScriptType);
begin
  Result := 'Ignore folders containing a flag file.';
  ScriptType := SCRIPTTYPE_RUN;
End;

Procedure RunBeforeFolderCompare(Foldername; var Skip);
begin
     if SBRunning.LeftFileExists(Foldername + '.nobackup') then
     begin
          // ShowMessage('I will skip ' + Foldername);
          Skip := True;
     end
End;

(side note: you cannot search the forum for the string "RunBeforeFolderCompare", it says the word is too common!)

I asked support, but they said they do not offer any scripting support whatsoever.

taviso
Newbie
Newbie
Posts: 2
Joined: Tue May 14, 2019 1:25 pm

Re: RunBeforeFolderCompare Does not skip requested Folders

Post by taviso » Tue May 14, 2019 3:38 pm

taviso wrote:
Tue May 14, 2019 1:33 pm
Hello, I am trying to skip folders that contain a specific file. I am using the RunBeforeFolderCompare hook, however no matter what I set the Skip variable to, the folder is never skipped.
I think I have a solution, I guess I'm the only person using this feature as there are zero hits anywhere for this hook :lol:

This seems to do what I want so far, maybe it will give a hint to anyone searching in future.

Please note, I'm a C programmer, I'm haven't written any Pascal since college... so I'm sure this is sub-optimal (1 indexed strings, wtf!)

Code: Select all

// 
// Ignore all files containing a flag file.
// SBLang=Pascal
//

function Description(var ScriptType);
begin
  Result := 'Ignore folders containing a flag file.';
  ScriptType := SCRIPTTYPE_RUN;
end
 
// If passed a file, return the containing directory.
// If passed a directory, return the parent directory.
function ParentDirectory(FileName);
begin
     Result := FileName;

     // Check for root directory.
     if Result = '\' then
        Exit;

     // Remove a character until we hit a directory separator.
     repeat
           Result := Copy(Result, 1, Length(Result) - 1);
     until Result[Length(Result)] = '\';

end

procedure RunBeforeFolderCompare(FolderName; var Skip);
begin
     // Check if this directory contains the flag file,
     // or any parent directory up until the root directory.
     repeat
          if SBRunning.LeftFileExists(FolderName + '.nobackup') then
             Skip := True;
          FolderName := ParentDirectory(FolderName);
     until FolderName = '\';
end


procedure RunBeforeFileCompare(FileName; var Skip);
    var FolderName;
begin
     // Find the name of the directory containing this file.
     FolderName := ParentDirectory(FileName);

     // Check if the containing directory has the flag file,
     // or any parent directory up until the root directory.
     repeat
          if SBRunning.LeftFileExists(FolderName + '.nobackup') then
             Skip := True;
          FolderName := ParentDirectory(FolderName);
     until FolderName = '\';
end

Post Reply