中的所有当前.pdf文件我需要做的是将test.pdf文件复制为当前已经在特定目录中的.pdf文件。将测试.pdf文件复制并重命名为目录
例如,该目录具有xyz.pdf,rgh.pdf,bne.pdf等
检验.pdf需要被重新命名为xyz.pdf,rgh.pdf,bne.pdf等 所有的.pdf文件应该有完全相同的内容,这就是为什么我需要将test.pdf重命名为目录中的每个.pdf文件。
这是我到目前为止尝试过的。它将测试文件“V2500SB.pdf”复制到正确的目录。目录中有两个.pdf文件,但不会将“V2500SB.pdf”重命名为目录中的文件。它在运行第一个文件后也停止。有任何想法吗?
try
{
$PDFDir = "D:\V2500Test\*"
$items = Get-ChildItem -Path ($PDFDir)
$ErrorActionPreference= 'continue'
$NewPDFDir = "D:\V2500SB.pdf"
$NewPDF = "V2500SB.pdf"
if (Test-Path -Path "$PDFDir")
{
# Code for directory not empty
# enumerate the items array
foreach ($item in $items)
{
Write-Host $item.Name
Copy-Item -Path $NewPDFDir -destination $PDFDir
Rename-Item $NewPDFDir + $NewPDF $PDFDir + $item -Force
}
}
else
{
Write-Host "No file to move"
exit
}
} #end of try
catch #Catch any fatal errors and send an email with description
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
$ErrorName = $_.Exception.GetType().FullName
$ExceptionBody = @"
Exception Name: $ErrorName
Exception Type: $FailedItem
Exception Message: $ErrorMessage
"@
} # end of catch
finally
{
}
注释掉catch块,看看你的脚本是否失败并报错。 –
您是否正在尝试在与另一个文件夹中的文件具有相同名称的文件夹中创建一组全新的文件?或者你是否试图替换现有文件夹中每个文件的内容? –