0

ユーザー指定のフォルダー内のすべてのファイルを取得し、それらを 1 つずつコマンド ラインに渡す Powershell スクリプトを作成しています。これにより、結果のファイル (.CSV) が別のユーザー指定のフォルダーにダンプされます。元のファイルと同じファイル名を CSV に使用しようとしています。このコマンドは、特定のフォルダー (C:\Program Files (x86)\Reporter) から実行する必要があります。

これは私がこれまでに持っているものですがwrite-host、ループ、反復、文字列など、名前を付けて、Powershell と私はブエノではありません。

pushd "C:\Program Files (x86)\Reporter\"

$filename = read-host "Enter the complete path of Original files"
$csvfiles = read-host "Enter the complete path for the CSVs"
write-host $filename
write-host $csvfiles
$reporter = "reporter.exe /rptcsv", $filename + ".csv", $filename

[$filename.string]::join(" ",(gci))

コマンド ライン コマンドは である必要がありますprogram.exe /rptcsv <file being created> <file being used>。一度に 1 つずつ処理する必要があり、前の処理が完了するのを待ってから 2 番目の処理を処理します。元のファイルの量はさまざまなので、すべてのファイルを処理するために必要なだけです。私はバッチ ファイルといくつかの Python を実行しましたが、Powershell を使用したことはありません。以前は Python でこれを行っていましたが、代わりに Powershell が必要になったと言われただけです。これはできますか?

編集:答えてください!!

これは作業コードです:

pushd "C:\Program Files (x86)\Reporter"

$src = read-host "Enter the complete path of the folder with original files"
$dst = read-host "Enter the complete path of the folder for the CSVs"
write-host $src
write-host $dst
$reporter = 'reporter.exe /rptcsv'

Get-ChildItem $src | % {
  $outfile = Join-Path $dst ($_.Name + ".csv")
  cmd /c $reporter $outfile $_.FullName
}
4

1 に答える 1

1

reporter.exe非同期に実行されない限り(つまり、バックグラウンドでファイルを処理している間、すぐには戻らない)、次のようなものが機能するはずです:

pushd "C:\Program Files (x86)\Reporter"

$src = read-host "Enter the complete path of the folder with original files"
$dst = read-host "Enter the complete path of the folder for the CSVs"
write-host $src
write-host $dst

Get-ChildItem $src | % {
  $outfile = Join-Path $dst ($_.Name + ".csv")
  reporter.exe /rptcsv $outfile $_.FullName
}
于 2013-06-03T18:28:07.910 に答える