【发布时间】:2016-07-25 00:37:41
【问题描述】:
我对 powershell 非常陌生,并且刚刚开始学习这个程序的深度。我的问题是我得到了大量的信息,我无法掌握所有这些信息,而且我迷失了许多相互矛盾的方法。这是我到目前为止所尝试的以及我收到的错误消息。如果有人能告诉我我做错了什么并且至少给出如何解决它的提示,我会很高兴。提前致谢。
脚本
$PlaylistName = Read-Host 'Playlist filename (Include drive and path):'
$Directory = Read-Host 'Target Directory (Include drive and path):'
Write-Host "Searching "$PlaylistName" for media files and copying to "$Directory"`n"
Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File Temp.txt
get-content Temp.txt | select-string -pattern "#EXTINF:0" -notmatch | Out-File Musiclist.txt
播放列表在这里:https://gist.github.com/zipster1967/ddc5ce0d81e70f3e59cf0dfb2b224704
当我运行此脚本时,我收到以下错误消息,但我不确定它的含义。
在 line:4 char:44 + 获取内容 $PlaylistName |其中 {$+.trim() -ne "" } |文件外温度... + ~ '(' 之后应该有一个表达式。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression
线
获取内容 $PlaylistName |其中 {$+.trim() -ne "" } |输出文件 Temp.txt
我来自http://www.pixelchef.net/remove-empty-lines-file-powershell
好的,根据建议,我现在有一个部分工作的脚本。我使用以下脚本将所有文件放入名为 Temp.txt 的文本文件中:
$PlaylistName = Read-Host 'Playlist filename (Include drive and path):'
$Directory = Read-Host 'Target Directory (Include drive and path):'
Write-Host "Searching "$PlaylistName" for media files and copying to "$Directory"`n"
Get-Content $PlaylistName | ? { $_ -and (Test-Path $_) } | Out-File Temp.txt
现在我只需要了解如何让 copy-item 命令读取 Temp.txt 文件并将文件复制到 $Directory 文件夹中。我的猜测是我需要添加该行
Get-Content Temp.txt | Copy-Item -Destination $Directory
我希望这是正确的。 (在 PowerShell 中还有很多东西要学。)
【问题讨论】:
-
$+是一个错误,应该是$_。 -
您的来源,pixelchef,显示了 $_ 而不是 $+ 的正确用法。
标签: powershell mp3 m3u