0
4

1 回答 1

0

这是 PowerShell 的起点,如果这对您有用:

#Look for any PDF format documents in K:\ CDS_TOOL_MANUAL_OVERRIDES folder.
$pdfFiles = Get-ChildItem -Path K:\CDS_TOOL_MANUAL_OVERRIDES -filter "*.pdf"

#For each document in K:\ CDS_TOOL_MANUAL_OVERRIDES look for PDF document with identical file name held in the \\mastercorrespondence” any sub-directory.
$referenceFiles = Get-ChildItem -Path \\mastercorrespondence -recurse -filter "*.pdf"
$pdfFiles | %{
    $_ = $pdfFile
    $matched = ""
    #I don't fully understand what you're asking for, but it seems to me that the move and rename are on the same file, and technically a rename is a move... so I've combined them.
    $referenceFiles | %{if ($_.Name -eq $pdfFile.Name) {$matched = $_}  }
    if ($matched -ne "") {
        $destinationName = ($pdfFile.Name + "_OverWritten_"+(Get-Date -format dd.MM.yy))
        Move-Item -Path $_.FullName -Destination ($matched.DirectoryName + "\" + $destinationName)
    }
    else{
        #If any documents did not have a corresponding file in \\mastercorrespondence sub-directory then write a message to log file stating names of unmatched files.
        ("Unable to locate matching file: " + $pdfFile.FullName) | Out-File -Append -FilePath "K:\mover.log"
    }
}
于 2012-07-20T15:31:03.037 回答