Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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下载时将文件名设置为默认值_Powershell_Web - Fatal编程技术网

如何在使用PowerShell下载时将文件名设置为默认值

如何在使用PowerShell下载时将文件名设置为默认值,powershell,web,Powershell,Web,刚开始在windows 7上使用powershell,我想从url中不包含文件名的站点下载一个文件。现在我正在使用 $webclient = New-Object System.Net.WebClient $src = "http://just-some-short-url/" $dest = "C:\Users\Downloads\some-file-2.53.jar" $webclient.DownloadFile($src,$dst) 这是可行的,但这仅仅是因为我用一些硬编码的值来指定名

刚开始在windows 7上使用powershell,我想从url中不包含文件名的站点下载一个文件。现在我正在使用

$webclient = New-Object System.Net.WebClient
$src = "http://just-some-short-url/"
$dest = "C:\Users\Downloads\some-file-2.53.jar"
$webclient.DownloadFile($src,$dst)
这是可行的,但这仅仅是因为我用一些硬编码的值来指定名称。但我真的只想说

$webclient = New-Object System.Net.WebClient
$src = "http://just-some-short-url/"
$dest = "C:\Users\Downloads\"
$webclient.DownloadFile($src,$dst)

因此,无论下载的是什么版本,都会在
C:\Users\Downloads\
中命名为这样的名称。例如,下个月,当我从同一链接获得的文件有新的更新时,我可能会有一个名为
some-file-2.54.jar的文件,但是后一个代码会抛出错误,并且只能通过硬编码来修复文件名。

获取帮助调用WebRequest…如果您在v3+上,URL是否包含文件名?如果有,您可以使用splitpath从URL获取文件名
$file=Split Path$src-leaf
@David
从url中不包含文件名的站点下载文件
查看我对几乎相同问题的回答。获取帮助调用WebRequest…如果您在v3+上,url是否包含文件名?如果有,您可以使用splitpath从URL获取文件名
$file=Split Path$src-leaf
@David
从url中不包含文件名的站点下载文件
查看我对几乎完全相同问题的回答。