Get only filename from full path of a file

后端 未结 2 835
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 09:39

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\\automatio         


        
2条回答
  •  一整个雨季
    2021-01-21 10:05

    You can also use the .Net implementation

    [System.IO.Path] is 10 times faster than the split-path cmdlet

    [System.IO.Path]::GetFileName('c:\myFile.txt')
    # result myFile.txt
    
    [System.IO.Path]::GetFileNameWithoutExtension('c:\myFile.txt') 
    # result myFile
    

    Performance comparision: 50.000 items

    [System.IO.Path]::GetFileName(...)    Average: 12,84143 
    
    Split-Path                            Average: 113,537884
    

提交回复
热议问题