Browse the docs

Split path

Splits a file path into its folder, name, name without extension and extension.

Split path into parts

Keyboard Maestro: SplitPath

Details #

Breaks a path into parts. It only works on the text of the path: the file does not have to exist and nothing on disk is read. A leading ~ is expanded to your home folder first.

For /Users/ana/Documents/report.final.pdf the parts are:

  • Directory: /Users/ana/Documents

  • Name: report.final.pdf

  • BaseName: report.final

  • Extension: pdf

The output is an object with those four parts. If you give into, the step also sets variables: into holds the whole (expanded) path, and the parts go in intoDirectory, intoName, intoBaseName and intoExtension. With into set to f, you can use {{fName}} and {{fExtension}} in later steps.

Parameters #

ParameterTypeRequiredValuesWhat it does
pathtextYesThe path to split. Required. Supports variables and expressions.
intotextThe prefix for the variables described above.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Split a path and show its parts
Do
  1. Split the path “~/Documents/report.final.pdf”
  2. Show “{{fBaseName}} is a .{{fExtension}} in {{fDirect…” for 3 s
Open in Switchboard to try it

Gotchas #

  • A name with no dot has an empty extension.

  • An empty path fails with "file.splitPath needs a path".

  • Like every step that is not marked safe, it is simulated in a dry run. The example turns on dryRunSafe because the step changes nothing.

See also #

File operation, Get or set a file attribute