Introduction to PowerShell for Unix People by Powershell.org - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

5. commands detail - b

basename

A rough PowerShell equivalent for the unix basename is:

img88.png

This depends on the file actually existing, whereas basename doesn’t care.

A more precise (but perhaps less concise) alternative[1] is:

[System.IO.Path]::GetFileName('c:\temp\double_winners.txt')

img89.png

Notes[1] I found [System.IO.Path]::GetFileName after reading Power Tips of the Day - Useful Path Manipulations Shortcuts, which has some other useful commands