私は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
このスクリプトを実行すると、次のエラー メッセージが表示され、意味がわかりません。
行:4 文字:44 + Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File Temp ... + ~ '(' の後に式が必要でした。 + CategoryInfo : ParserError: (:) []、ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression
この線
Get-Content $PlaylistName | where {$+.trim() -ne "" } | Out-File 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 について学ぶことはまだたくさんあります。)