copying pdf files into folders

i have 10 pdf files in folder, i want copying those files in folders on another location, but if statement is name folders must be same like contain in files. then if contain file for example john smith, this file will copy in folder with name john smith.

i have code which works on txt files

$folder=get-childitem V:\ ; $file=get-childitem c:\test\ -filter*.txt-recurse; foreach($foldernamein$folder){foreach($filenamein$file){$filecopy=$filename|get-content-filter$foldername.Name; if($filecopy-eq$foldername.Name){copy-item$filecopy.PSPath$foldername.FullName; }}}

i have code for reading one pdf file

[System.Reflection.Assembly]::LoadFrom("C:\Scripts\PdfToText\itextsharp.dll")
Add-Type -Path 'C:\Scripts\PdfToText\itextsharp.dll'
 
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList "$pwd\test.pdf"
 
for ($page = 1; $page -le $reader.NumberOfPages; $page++) {
 $lines = [char[]]$reader.GetPageContent($page) -join "" -split "`n"
 foreach ($line in $lines) {
  if ($line -match "^\[") {   
   $line = $line -replace "\\([\S])", $matches[1]
   $line -replace "^\[\(|\)\]TJ$", "" -split "\)\-?\d+\.?\d*\(" -join ""
  }
 }
}

how connect both codes or maybe the better solution?

thanks


  • Edited by gogi1000 Friday, May 22, 2015 1:08 PM error
May 22nd, 2015 1:05pm

i writed code for copying files. if content of file is same like folder's name this file is copying in this folder. code is

$folder=get-childitem V:\ ;
$file=get-childitem c:\test\ -filter*.txt-recurse; 
foreach($foldernamein$folder){foreach($filenamein$file){$filecopy=$filename|get-content-filter$foldername.Name;
if($filecopy-eq$foldername.Name){copy-item$filecopy.PSPath$foldername.FullName;
}}

this code works on text files, but not on pdf files. on internet i found code for read one pdf

[System.Reflection.Assembly]::LoadFrom("C:\Scripts\PdfToText\itextsharp.dll")
Add-Type -Path 'C:\Scripts\PdfToText\itextsharp.dll'
 
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList "$pwd\test.pdf"
 
for ($page = 1; $page -le $reader.NumberOfPages; $page++) {
 $lines = [char[]]$reader.GetPageContent($page) -join "" -split "`n"
 foreach ($line in $lines) {
  if ($line -match "^\[") {   
   $line = $line -replace "\\([\S])", $matches[1]
   $line -replace "^\[\(|\)\]TJ$", "" -split "\)\-?\d+\.?\d*\(" -join ""
  }
 }
}
how i use this code for my problem or you have the better solution? maybe i need convert those files in docx and then reading docx. if you have solution for this problem and this solution is welcome


  • Edited by gogi1000 Friday, May 22, 2015 6:37 PM error writing
Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2015 6:33pm

I search text first and last name of user in content of files
  • Edited by gogi1000 Friday, May 22, 2015 7:17 PM error read
May 22nd, 2015 7:16pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics