Skip to content

Filepath Op

Performs various string operations on file paths, like extracting the base name, directory, or extension.

Inputs#

Port Description
Path
The file path to operate on.
The operation to perform on the path.

Outputs#

Port Description
The result of the operation.

Addendum#

Performs a string-based operation on the input file path.

Operations Overview#

  • Base: Extracts the last element of a path (e.g., the file or folder name).
  • Clean: Returns the shortest, lexically equivalent path.
  • Dir: Extracts the directory part of a path.
  • Ext: Extracts the file extension.
  • From Slash: Converts / to the OS-specific path separator (e.g., \ on Windows).
  • To Slash: Converts OS-specific path separators to /.
  • Volume: Extracts the volume name (e.g., C: on Windows).

1. Base#

Returns the last element of the path. Trailing separators are removed before extracting the last element.

Style Input Path Output
POSIX /home/user/file.txt file.txt
POSIX /home/user/ user
Windows C:\Users\user\file.txt file.txt
Any (empty) .

2. Clean#

Returns the shortest path name equivalent to path by purely lexical processing. It simplifies paths by removing . and resolving .. elements.

Style Input Path Output
POSIX /home/user/../other/file.txt /home/other/file.txt
POSIX /home/user/./file.txt /home/user/file.txt
Windows C:\Users\..\other\file.txt C:\other\file.txt

3. Dir#

Returns all but the last element of the path, which is typically the path's directory.

Style Input Path Output
POSIX /home/user/file.txt /home/user
POSIX /home/user/ /home
POSIX file.txt .
Windows C:\Users\user\file.txt C:\Users\user

4. Ext#

Returns the file name extension. The extension is the suffix beginning at the final dot; it is empty if there is no dot.

Input Path Output
archive.tar.gz .gz
image.jpeg .jpeg
file (empty)
config. .

5. From Slash#

Replaces all forward slashes (/) with the OS-specific path separator. This has no effect on POSIX systems.

Platform Input Path Output
POSIX /home/user/file.txt /home/user/file.txt
Windows C:/Users/user/file.txt C:\Users\user\file.txt

6. To Slash#

Replaces all OS-specific path separators with forward slashes (/). This has no effect on POSIX systems.

Platform Input Path Output
POSIX /home/user/file.txt /home/user/file.txt
Windows C:\Users\user\file.txt C:/Users/user/file.txt

7. Volume#

Returns the leading volume name. On Windows, this can be a drive letter (C:) or a UNC path (\\host\share). On POSIX systems, it returns an empty string.

Style Input Path Output
POSIX /home/user/file.txt (empty)
Windows C:\Users\file.txt C:
Windows \\host\share\path \\host\share
Any (empty) (empty)

ID: core/filepath-op@v1