os.Path.dirName

Returns all components of a path excluding the last one.

Syntax

os.Path.dirName(
   filename STRING)
  RETURNING result STRING
  1. filename is the name of the file.
  2. result contains all the elements of the path excluding the last one.

Usage

This method removes the last component of a path provided as argument.

For example, if you pass "/root/dir1/file.ext" as the parameter, it will return "/root/dir1".

See Example 1: Extracting the parts of a file name for more examples.