Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only filename from full path of a file

Tags:

powershell

I want to split the path and just save the file name test.xls in a new variable

$namearray = "C:\Users\z003m\Desktop\Service_Tickets\automationscript\vbs\Newfolder\test.xls"
like image 967
sud Avatar asked Dec 18 '22 07:12

sud


1 Answers

Recommend using the built-in Split-Path:

$newVariable = Split-Path $namearray -Leaf
like image 182
G42 Avatar answered Feb 19 '23 04:02

G42