Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell PS1:如何从行中排除单词_Powershell - Fatal编程技术网

Powershell PS1:如何从行中排除单词

Powershell PS1:如何从行中排除单词,powershell,Powershell,在这种情况下,如何排除此行的文件路径部分 链接: 可以是.exe、.zip等 产出目标: file.exe 也希望如此使用它: $x = file.exe $path = C:\Users\Downloads\$x 如何使用powershell实现这一点?我建议您在询问之前多搜索一点。 我确实很容易在5分钟内在线找到解决方案 $link = 'www.website.com/downloads/file.exe' $lastSlashPos = $link.LastIndexOf('/'

在这种情况下,如何排除此行的文件路径部分

链接:

可以是.exe、.zip等

产出目标:

file.exe
也希望如此使用它:

$x = file.exe

$path = C:\Users\Downloads\$x

如何使用powershell实现这一点?

我建议您在询问之前多搜索一点。
我确实很容易在5分钟内在线找到解决方案

$link = 'www.website.com/downloads/file.exe'

$lastSlashPos = $link.LastIndexOf('/')
$fileNameWithExtension = $link.Substring($lastSlashPos+1)
文章:


您可以使用带有参数
-leaf
分割路径
cmdlet:

'www.website.com/downloads/file.exe' | Split-Path -leaf

将有一个
file.exe

的输出,它可能会帮助您阅读。这里最方便的方法可能是使用.Net类:
$fileName=[System.IO.Path]::GetFileName('www.website.com/downloads/file.exe')#-->file.exe
'www.website.com/downloads/file.exe' | Split-Path -leaf