Skip to content

win_basename

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.0.

Synopsis

  • Returns the last name component of a Windows path, what is left in the string that is not 'win_dirname'.
  • While specifying an UNC (Universal Naming Convention) path, please make sure the path conforms to the UNC path syntax.

Parameters

Parameter Defaults / Choices Comments
_input
str
required
A Windows path.

Examples

# To get the last name of a file Windows path, like 'foo.txt' out of 'C:\Users\asdf\foo.txt'
filename: "{{ mypath | win_basename }}"

# Get basename from the UNC path in the form of '\\<SERVER_NAME>\<SHARE_NAME>\<FILENAME.FILE_EXTENSION>'
# like '\\server1\test\foo.txt' returns 'foo.txt'
filename: "{{ mypath | win_basename }}"

Return Values

Key Data Type Description Returned
_value str The base name from the Windows path provided.

Authors

  • Ansible Core Team