Read text after last backslash

前端 未结 4 1164
生来不讨喜
生来不讨喜 2021-01-12 18:08

I am would like to read in the text after the last backslash from my text file. Currently I have:

$data=Get-Content \"C:\\temp\\users.txt\"
<
4条回答
  •  别那么骄傲
    2021-01-12 18:31

    Since you are dealing with file paths, you can use GetFileName:

    $data=Get-Content "C:\temp\users.txt"
    $name=[System.IO.Path]::GetFileName($data)
    

提交回复
热议问题