首页 > 解决方案 > Visual Studio PowerShell 使列表框拖放文件可用

问题描述

listbox在我的 Windows 窗体中设置了一个可以将文件拖放到其中的设置,我想要实现的第一件事是只显示文件名而不是路径,请参见下面的代码块。

$handler = {
  $_.Data.GetFileDropList() | % {
    $listbox1.Items.Add($_)
  }
}
$listbox1.AllowDrop = $true
$listbox1.Add_DragEnter({$_.Effect = [Windows.Forms.DragDropEffects]::Copy})
$listbox1.Add_DragDrop($handler)

PowerShell第二个目标是能够.pdflistbox1.

在此处输入图像描述

我的.pdf组合脚本如下

$button2_Click = {

$pdftk = "C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe"
$inputFolder = "E:\SIGNEDNOTES"
$outputFolder = "E:\out\"

$IntactScan = Get-ChildItem $inputFolder -File | Measure-Object | % {$_.Count}

If ($IntactScan -gt $maxItems) {

   Get-Childitem $inputFolder -filter *.pdf -Recurse 
   pdftk "E:\SIGNEDNOTES\*.pdf" cat Output $outputFolder\Rename.pdf

   Move-Item "E:\SIGNEDNOTES\*.pdf" "E:\Backup\"
}
else {
    exit
}
}

基本上我希望用户能够将 2 x pdf 文件拖入listBox1并按下组合按钮并将组合输出.pdf到第二个listBox2

标签: powershellvisual-studio-2019

解决方案


关于我的第一个问题,这正在进行中,但在 2 中不太重要的一个

我通过下面的代码解决了另一个问题(组合来自 listBox 的 2 个 pdf)



$pdftk = "C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe"
$inputFolder = $listbox1.Items
$outputFolder = "E:\out"

$CountyCount = Get-ChildItem $inputFolder -File | Measure-Object | % {$_.Count}

If ($CountyCount -gt $maxItems) {

   Get-Childitem $inputFolder -filter *.pdf -Recurse 
   pdftk $listbox1.Items cat Output $outputFolder\Combine.pdf

    $listbox1.Items.Clear()

    #Move-Item "E:\SIGNEDNOTES\*.pdf" "E:\Backup\"
}
else {
    exit
}

}```

thank you for your help

推荐阅读