Skip to content

Rule reference

A routing has two parts: General, with the scan and log options, and FileMatching, with the list of rules. In the database mode, the routing is maintained in the Riversoft® Console Portal and can be exported with -export. In the local file mode, it is a JSON file created from the example-config_rules.json template.

{
  "General": { "Name": "INBOUND", "ScanDir": "/mailbox/IN", "LogLevelOnSuccess": 6, "LogLevelOnError": 1 },
  "FileMatching": [
    {
      "Index": 0,
      "Name": "NOTES",
      "FileRegEx": "^NOTES.*\\.TXT$",
      "General": { "SourceUser": "PARTNER", "WeekDayInterval": 127, "EndDateHour": 23, "EndDateMinute": 59, "EndDateSecond": 59 },
      "Filename": { "RenameFileTo": "" },
      "Copy": { "CopyToDir": "/mailbox/OUT", "CopyFileOption": 13 },
      "Backup": { "BkpToDir": "/backup/notes", "BkpFileOption": 4 }
    }
  ]
}

Text fields accept regular expressions in RE2 syntax. Numeric fields marked as options are sums of values: to combine options, add the values, for example 1 + 4 + 8 = 13.

Routing General

FieldDescription
Name, DescriptionRouting name and description.
ScanDirScan directory. The -scan option takes precedence.
ScanSubDir0: the directory only; 1: subdirectories only; 2: the directory and its subdirectories. The -nosubdir, -subdir and -subdir2 options take precedence.
ScanDirRegEx, ScanDirRegExNegExpressions that include or exclude directories from the scan.
ScanFileRegEx, ScanFileRegExNegExpressions that include or exclude files from the scan.
ScanFirstRuleNumber (Index) of the first rule evaluated. Default: 0.
ScanLockSemName of the semaphore that prevents two simultaneous scans with the same name.
ScanLockSemTimeoutMaximum wait for the semaphore, in milliseconds. -1 waits with no limit.
ScanLockSemOptionsOptions. 1: exits immediately if the semaphore is in use.
LogErrorOptionOptions. 1: records an error when the file cannot be read; 2: records an error when a directory cannot be read.
LogLevelOnSuccess, LogLevelOnWarning, LogLevelOnInfo, LogLevelOnErrorLevel of the rule success, warning, information and error messages. Defaults: 6, 7, 7 and 1. See Message levels.
ScanCheckFileInUse, DelayRetry, MaxRetriesKept for compatibility. Not used in this version.

File selection

Each FileMatching item is a rule. Rules are evaluated in Index order, and the first one that matches the file applies.

FieldDescription
IndexRule number, from 0, with no gaps. A gap ends the evaluation.
Name, DescriptionRule name and description. Available in $RULENAME and $DESCR.
Locked1 locks the rule, which is then ignored.
FileRegExExpression applied to the file name.
DirRegExExpression applied to the file directory.
SrcRegExExpression applied to the source given in -src.
ContentRegExExpression applied to the first lines of the file. The number of lines is set in General.ContentLinesToRead.

An empty field accepts any value.

Note

When ContentRegEx is filled in and the content does not match, processing of the file ends with an error, without evaluating the following rules. Use FileRegEx and DirRegEx to separate the files before checking the content.

Rule General

FieldDescription
SourceUser, DestinationUserSource and destination users associated with the rule. Available in $SRCUSER and $DSTUSER and used when recording messages.
ExecProgBeforeCommand run before the copy.
ExecProgCommand run after the copy.
ExecProgErrorCommand run when a step fails.
CheckLockUnlockFileNameControl file checked before processing and removed at the end. Accepts variables.
CreateLockUnlockFileNameControl file created during processing. Accepts variables.
CheckLockUnlockOptionControl file options. See Control files.
RemoveAfterCopy1 removes the original file at the end of processing.
RemoveAfterHoursWith RemoveAfterCopy, removes the original only if it is older than the given number of hours. 0: always removes it.
ProcessAfterSecondsMinimum age of the file, since its last modification, for it to be processed. The value is read in milliseconds. 0 disables it.
InsertTimestampOptions. 1: appends the date and time to the end of the name; 2: adds it to the start. The separator is ..
InsertTimestampPartSource of the date and time: 0, current time; 1, 2 or 3, file modification date.
InsertTimestampFormatDate and time format, written with the reference date 2006-01-02 15:04:05. Example: 20060102150405 produces YYYYMMDDhhmmss. Empty: YYYYMMDDhhmmss0mmm.
DelayNextFileProcessPause after processing the file, in milliseconds.
StartDateHour, StartDateMinute, StartDateSecondStart of the allowed time.
EndDateHour, EndDateMinute, EndDateSecondEnd of the allowed time.
WeekDayIntervalAllowed days: add 1 (Sunday), 2 (Monday), 4 (Tuesday), 8 (Wednesday), 16 (Thursday), 32 (Friday) and 64 (Saturday). 127 or 255: every day.
FileLenOptionOptions. 1: checks the minimum size; 2: checks the maximum size.
FileLenMin, FileLenMaxMinimum and maximum sizes, in bytes.
ReplaceFromFileOption1 enables building the name from the content (Filename.ReplacesFromFile).
ContentLinesToReadNumber of lines read for ContentRegEx.
OtherOptionOptions. 2: resets the sequence number every day.
NextSectionName of the next rule to run on the same file.
OverwriteKept for compatibility. To overwrite, use the Copy and Backup options.

When the file is outside the allowed time, day, age or size, processing ends with a warning.

New name (Filename)

The new name is built in this order:

  1. Starts from RenameFileTo. Empty: the new name starts empty and, if nothing is added, the original name is kept.
  2. Applies ReplacesFromFile, when enabled in ReplaceFromFileOption.
  3. Applies Replaces, in order.
  4. Adds the date and time, according to InsertTimestamp.
  5. Applies ReplacesByRegEx, in order.

Replaces

Each item copies a piece from a source into the new name. Positions start at 1.

FieldsSource of the piece
ReplaceFileNamePosFrom, ReplaceFileNamePosTo, ReplaceFileNameLenOriginal file name.
ReplaceFileNameFromPathPosFrom, ReplaceFileNameFromPathPosTo, ReplaceFileNameFromPathLenOriginal file directory.
VarReplaceFileNamePosFrom, VarReplaceFileNamePosTo, VarReplaceFileNameLen, VarReplaceFileNameValueFixed value. The -var0 value replaces the first item’s value, -var1 the second item’s, and so on.
InsertTimestampPosFrom, InsertTimestampPosTo, InsertTimestampLenDate and time.
InsertSeqNumberTo, InsertSeqNumberLen, InsertSeqNumberMin, InsertSeqNumberMaxSequence number with leading zeros, from Min to Max, which returns to the minimum after the maximum.
  • ...PosFrom: start position of the piece in the source. 0: start.
  • ...PosTo: position in the new name where the piece is written, overwriting what is there. 0 or -1: appends to the end.
  • ...Len: number of characters. 0 disables the item.

The last sequence number used is kept in the applLockDir directory. InsertSeqNumberSeq is kept for compatibility.

Example: for the file NF20261110.TXT, the item below produces 20261110, copying 8 characters from position 3:

{ "ReplaceFileNamePosFrom": 3, "ReplaceFileNamePosTo": -1, "ReplaceFileNameLen": 8 }

ReplacesFromFile

Copies into the new name a piece of the first line of the file that matches the expression.

FieldDescription
ReplaceFromFileRegExExpression that finds the line.
ReplaceFromFilePosFrom, ReplaceFromFilePosTo, ReplaceFromFileLenPiece of the line copied, with the same rules as Replaces.
ReplaceFromFileNext1 keeps reading the following lines after finding this one.

ReplacesByRegEx

Replaces in the new name each occurrence of RegExReplaceFrom with RegExReplaceTo. Use ${1}, ${2} for the groups and ${0} for the matched text. Example: "RegExReplaceFrom": "(?i)\\.txt$", "RegExReplaceTo": ".csv". RegExReplaceOcorr is kept for compatibility.

Copy (Copy)

FieldDescription
CopyToDirDestination directory. Empty: the original file directory. The -copydir option takes precedence.
CopyFileOptionCopy options. See the table below.
ReplacesBuilds the destination directory by positions, as in Filename.Replaces, with the PathReplace... (original directory), PathReplaceFromFileName... (file name), PathInsertTimestamp... (date and time) and PathVarReplace... (fixed value or -var0 to -var9) fields.
ReplacesByRegExRegular expression replacements in the destination directory.
CopyTempExtension, CopyFileRecSizeKept for compatibility. Not used in this version.
ValueCopyFileOption option
1Performs the copy. Without this option, there is no copy.
4Creates the destination directory if it does not exist.
8Moves the file instead of copying it.
16Overwrites the destination file. Without this option, the copy fails if the destination exists.
64Inserts CR before each LF (Windows format).
128Removes CR characters (Linux format).
512Converts the new name to lowercase.
1024Converts the new name to uppercase.

Backup (Backup)

FieldDescription
BkpToDirBackup directory. The -backupdir option takes precedence.
BkpFileOptionBackup options. 0: no backup. With any other value, the backup is made; also set BkpToDir.
Replaces, ReplacesByRegExBuild the backup directory, as in Copy.
ValueBkpFileOption option
1Uses the new name in the backup. Without this option, uses the original name.
4Creates the backup directory if it does not exist.
16Overwrites the existing backup.
32Makes the backup before the copy. Without this option, the backup is made after the copy.
64, 128Inserts CR before LF or removes CR.
256Appends the date and time to the end of the backup name.

Control files

Control files signal to other processes that a file is being processed or is ready. The names accept variables, for example $PATHOLDNAME/$OLDNAME.lck.

ValueCheckLockUnlockOption option
2Before processing, requires CheckLockUnlockFileName to exist.
4Before the ExecProgBefore command, creates CreateLockUnlockFileName. Fails if it already exists.
8After the copy, creates CreateLockUnlockFileName.
16At the end, removes CreateLockUnlockFileName.
32At the end, removes CheckLockUnlockFileName.

External commands

ExecProgBefore, ExecProg and ExecProgError receive a command with arguments, for example:

/usr/local/bin/notify.sh "$FILENEWNAME" $SRCUSER $DSTUSER
  • Variables are replaced before the run. See Variable reference.
  • The command runs directly, without a shell: use the full path and, for redirections or pipes, call a script.
  • Arguments in double or single quotes are passed without the quotes.
  • Riversoft STCP Gemini Rename waits for the command to finish. An exit code other than 0 is treated as a failure.