【发布时间】:2017-11-29 17:36:32
【问题描述】:
我目前有一个脚本,它将遍历文件夹中的一组文件 - 打开每个文件,让我输入一个新文件名,然后重命名它。然后,我尝试创建一个 CSV 文件,其中一列中的旧名称和第二列中的文件的新名称。
#[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
Add-Type -AssemblyName Microsoft.VisualBasic
$folderpath = 'C:\Scans\docs\' '#
$items = Get-ChildItem -Recurse $folderpath *.pdf
$newFileName = ""
$counterID = 0
$amountOfScans = $items.Length
foreach( $i in $items) {
Start-Process ((Resolve-Path ("$folderpath$i")).Path)
Start-Sleep -Seconds 1
$counterID++
$newFileName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the new file name $counterID / $amountOfScans :", $i)
Stop-Process -Name "Acro*"
Add-Content -Path 'C:\Scans\fileNames.csv' -Value "$i","$newFileName "
Rename-Item $i.FullName ("$newName.pdf")
}
这确实有效,但它仅在第一列中输出到 csv,例如:
旧文件名 1 新文件名 1 旧文件名 2 新文件名 2如何输出:
旧文件名 1 |新文件名 1 旧文件名 2 |新文件名 2【问题讨论】:
标签: powershell csv