0

PDFファイルを取得し、このPDFファイルをソースから宛先にコピーする必要があります。PDF名はtxtファイルlistspecに1行ずつあります:

100
200 
204 
79002 
XS002

.pdf拡張子を連結します

ただし、pdf ファイルは 001 00 .pdf、002 00 .pdf、204 00 .pdf、79002.pdf、XS002.pdf です。最大5つの位置でpdfファイル名を0にしてパッドレフトする必要があります。

私はこのコマンドを使用します:

Get-Content $listspec | Foreach-Object{copy-item -Path $source\$_".pdf".PadLeft(5,'0'), -destination $destination -ErrorAction SilentlyContinue -ErrorVariable +errors} 

次のエラーが表示されます。

*Copy-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter ' method is not supported.*

ご協力いただきありがとうございます。

4

2 に答える 2

0

これは単純なタイプミスの問題です。との,間のコンマを削除します。-path-destination

これの代わりに:

copy-item -Path $source\$_".pdf".PadLeft(5,'0')-destination $destination

次のような構文を使用します。

copy-item -Path $source\$_".pdf".PadLeft(5,'0') -destination $destination

于 2015-04-30T05:56:01.757 に答える
0

files.txtこれは、指定されたファイルをフォルダーにコピーするのに役立ちますdest

gc .\files.txt | % { Copy-Item ($_.padRight(5,"0")+".pdf") -Destination "dest\ " }

Copy-Itemコマンドレットに渡す前に、ファイル名をラップして評価する必要がありました

これ: ( $_.padRight(5,"0")+".pdf")

于 2015-04-30T14:36:42.903 に答える