gpt4 book ai didi

powershell - 测试路径 : Illegal characters in path

转载 作者:行者123 更新时间:2023-12-03 00:36:22 24 4
gpt4 key购买 nike

我正在尝试使用 powershell 从 channel9 下载视频系列,但是我在第一个文件上遇到了这个错误,我认为它是管道字符,但即使使用替换语句它也不起作用

 function Get-Media
{
[CmdletBinding()]
param
(
[Object]
$url,
[Object]
$title,
[Object]
$path
)

$u = New-Object System.Uri($url)
$name = $title
$extension = [System.IO.Path]::GetExtension($u.Segments[-1])
$fileName = $name + $extension

$fileName = $fileName -replace "’", ''
$fileName = $fileName -replace "\?", ''
$fileName = $fileName -replace ":", ''
$fileName = $fileName -replace '/', ''
$fileName = $fileName -replace ",", ''
$fileName = $fileName -replace '"', ''
$fileName = $fileName -replace '|', ''
$fileName = $fileName -replace '\#', ''
$fileName = $fileName -replace '-', ''

$fileName

if (Test-Path($fileName)) {
Write-Host 'Skipping file, already downloaded' -ForegroundColor Yellow
}
else
{
Invoke-WebRequest $url -OutFile (Join-Path -Path $path -ChildPath $fileName)
}
}

function Get-VideosFromFeed
{
[CmdletBinding()]
param
(
[Object]
$feedUrl,
[Object]
$folder,
[Object]
$path
)

$feed=[xml](New-Object System.Net.WebClient).DownloadString($feedUrl)

$downloadPath = (Join-Path -Path $path -ChildPath $folder)

if (Test-Path($downloadPath)) {
Write-Host 'Skipping folder, already exists' -ForegroundColor Yellow
}
else
{
New-Item -Path $downloadPath -ItemType directory -WarningAction SilentlyContinue
}

foreach($i in $feed.rss.channel.item) {
foreach($m in $i.group){
foreach($u in $m.content `
| Where-Object { `
$_.url -like '*mid.mp4' `
} | Select-Object -Property @{Name='url'; Expression = {$_.url}}, `
@{Name='title'; Expression = {$i.title}})
{
Get-Media -url $u.url -title $u.title -path $downloadPath
}
}
}
}

$physicalPath = "D:\Videos\Series"

Get-VideosFromFeed -feedUrl 'https://channel9.msdn.com/Blogs/azurestack/feed/mp4high' -path $physicalPath -folder 'azurestack'

最佳答案

你也可以试试这个:

$FileName.Split([IO.Path]::GetInvalidFileNameChars()) -join ''

对我来说似乎很有效:)

关于powershell - 测试路径 : Illegal characters in path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38044236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com