Prototype: translatepath(path)

Return type: string

Description: Translate separators in path from Unix style to the host's native style and returns the result.

Takes a string argument with slashes as path separators and translate these to the native format for path separators on the host. For example translatepath("a/b/c") would yield "a/b/c" on Unix platforms, but "a\b\c" on Windows.

Arguments:

  • path: string, in the range: "?(/.*)

Example:

body common control
{
      bundlesequence => { "test" };
}

bundle agent test
{
  vars:
      "inputs_dir" string => translatepath("/a/b/c/inputs");

  reports:

    windows::
      "The path has backslashes: $(inputs_dir)";

    !windows::
      "The path has slashes: $(inputs_dir)";
}

Output:

R: The path has slashes: /a/b/c/inputs

Notes: Be careful when using this function in combination with regular expressions, since backslash is also used as escape character in regex's. For example, in the regex dir/.abc, the dot represents the regular expression "any character", while in the regex dir\.abc, the backslash-dot represents a literal dot character.