Table of Contents

rename

Description

Renames a specified file.

Syntax

rename -filePath -value -search

Parameters

  • filePath: The filerename.

  • directory: The directory to rename.

  • value: The new name for the file. You must include the extension.

  • search: The search operation to use.

Examples

rename -filePath "oldname.sldprt" -val "newname.sldprt"

Remarks

  • The search parameter searches the current directory and does not drill down. The search query is a PDM one, so you can use % for wildcard.

Value Evaluation

The value parameter gets evaluated by PDMShell. PDMShell allows you to use placeholders in the new name, which will be replaced with actual values from the file. This can be useful to dynamically generate new names based on file properties or other variables. The following placeholders are supported:

  • $filename - The file name without extension.
  • $id - The file ID.
  • $revision - The current revision of the file.
  • $date - The current date.
  • $time - The current time.
  • $version - The current version of the file.
  • $extension - The file extension.

Additionally, you can use variables enclosed in square brackets (e.g., [VariableName]) to include values from other variables.

String functions are also supported after placeholders are evaluated. For example, ${replace($fileNameWithoutExtension, " ", "_")} replaces spaces in the file name before the rename value is written. Use ${before($fileNameWithoutExtension, "-")} to keep only the part of the name before a separator.

Note

Please read more information about placeholder evaluation here.

Examples

If you use the value "$filename_$date_$version$extension", it will be replaced with the file name, current date, and version, resulting in something like "oldname_10-12-2023_3".

rename -filePath "Part 123 Draft.sldprt" -value "${left(${replace($fileNameWithoutExtension, \" \", \"_\")}, 12)}$extension"

rename -filePath "ABC-123.sldprt" -value "${before($fileNameWithoutExtension, \"-\")}$extension"

Availability

Available since PDMShell 2.0.0.