
해당 pdftotext 줄 및/또는 pdfinfo 제목에서 pdf 파일의 이름을 바꾸는 powershell 스크립트를 만들고 싶습니다. 먼저 특정 경로에 있는 PDF 파일의 다중 선택 목록을 만들고 이름을 바꾸려는 목록에서 PDF 파일을 선택하고 싶습니다. gci 명령을 통해 파이프될 수 있는 파일 이름에서 선택 목록을 만드는 데 도움을 줄 수 있는 사람이 있습니까?
답변1
모든 의견에 감사드립니다. 다음은 해당 텍스트 또는 메타데이터에서 PDF 파일의 이름을 바꾸는 코드입니다. 나는 IT 전문가가 아니기 때문에 코드는 매우 원시적입니다. 단지 다른 사람들에게서 조각을 빌려서 모은 것뿐입니다.
$x = @() function Read-OpenFileDialog([string]$WindowTitle, [string]$InitialDirectory, [string]$Filter = "모든 파일 (*.*)|*.*", [switch]$AllowMultiSelect) { 추가 유형 -AssemblyName System.Windows.Forms $openFileDialog = 새 개체 System.Windows.Forms.OpenFileDialog $openFileDialog.Title = $WindowTitle if (![string]::IsNullOrWhiteSpace($InitialDirectory)) { $openFileDialog.InitialDirectory = $InitialDirectory } $openFileDialog.Filter = $Filter if ($AllowMultiSelect) { $openFileDialog.MultiSelect = $false } $openFileDialog.ShowHelp = $true # 이 줄이 없으면 ShowDialog() 함수는 시스템 구성 및 콘솔과 ISE에서 실행되는 방식에 따라 중단될 수 있습니다. $openFileDialog.ShowDialog() > $null if ($AllowMultiSelect) { $openFileDialog.Filenames 반환 } else { $openFileDialog.Filename 반환 } } $file = 읽기-OpenFileDialog -WindowTitle "PDF 문서 섹션" -InitialDirectory '$path' -Filter "PDF 파일(*.pdf)|*.pdf" if (![string]::IsNullOrEmpty($file)) { Write-Host "파일을 선택했습니다: $file" } else { "Dosya seçmediniz" } $path= "$file"|분할 경로 CD $경로 [공허] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.드로잉") $objForm = 새 개체 System.Windows.Forms.Form $objForm.Text = "FORMU 형식" $objForm.Size = 새 개체 시스템.드로잉.크기(700,400) $objForm.StartPosition = "센터스크린" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") { $x=$objListbox.SelectedItem;$objForm.Close() } }) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) $OKButton = 새 개체 System.Windows.Forms.Button $OKButton.Location = 새 개체 System.드로잉.크기(75,220) $OKButton.Size = 새 개체 System.드로잉.크기(75,23) $OKButton.Text = "EVET" $objForm.Controls.Add($OKButton) $OKButton.Add_Click({$x=$objListbox.SelectedItem;$objForm.Close()}) $CancelButton = 새 개체 System.Windows.Forms.Button $CancelButton.Location = 새 개체 시스템.드로잉.크기(200,220) $CancelButton.Size = 새 개체 System.드로잉.크기(75,23) $CancelButton.Text = "임시 동부 표준시" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel = 새 개체 System.Windows.Forms.Label $objLabel.Location = 새 개체 시스템.드로잉.크기(10,20) $objLabel.Size = 새 개체 시스템.드로잉.크기(480,20) $objLabel.Text = "야핀 검색 목록:" $objForm.Controls.Add($objLabel) $objListbox = 새 개체 System.Windows.Forms.Listbox $objListbox.Location = 새 개체 System.드로잉.크기(10,40) $objListbox.Size = 새 개체 System.드로잉.크기(600,840) $objListBox.Font = "아리알 블랙" pdftotext -eol dos -l 2 $file tmp.txt (gc tmp.txt) | ? {$_.trim() -ne "" } | 콘텐츠 설정 tmp.txt $i=pdfinfo "$file" |grep -i title|sed -e 's/Title\:[ ]*//g' If (![문자열]::IsNullOrEmpty($i)) { $line6=$i } $line1= (Get-Content tmp.txt)[0] $line2= (Get-Content tmp.txt)[1] $line3= (Get-Content tmp.txt)[2] $line4= (Get-Content tmp.txt)[3] $line5= (Get-Content tmp.txt)[4] [공허함] $objListbox.Items.Add("$line1") [공허] $objListbox.Items.Add("$line2") [공허함] $objListbox.Items.Add("$line3") [공허함] $objListbox.Items.Add("$line4") [공허함] $objListbox.Items.Add("$line5") [공허함] $objListbox.Items.Add("$line6") $objListbox.Height =170 $objForm.Controls.Add($objListbox) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [무효] $objForm.ShowDialog() $z= $objListbox.SelectedItems if ($z -ne ""){ $z= $z - '[^a-zA-Z0-9_ ]',"_" 교체 $z= $z - '[ ]' 교체,"_" $z= $z - '_{2,}',"_" 교체 $z= $z.트림() 쓰기 호스트 "dosya $z.pdf olarak kaydedildi" 이름 바꾸기 항목 $file -newname $z".pdf" } Else {쓰기 호스트 "isim değişmedi"} rmtmp.txt 정지시키다 $x