i have code for copying 10 pdf files in 10 folders. i want copying those files in folders on another location and if statment is name folders must be same like contain in files. then if contain file for example john smith, this file wil copy in folder with name john smith
[System.Reflection.Assembly]::LoadFrom("C:\Scripts\PdfToText\itextsharp.dll")
Add-Type -Path "C:\Scripts\PdfToText\itextsharp.dll"
$destinationFolders = Get-ChildItem V:\ -Directory
$files = Get-ChildItem C:\Test -Filter *.pdf -Recurse -File
foreach ($file in $files) {
#Reset flag for match for each file
$foundMatch = $false
#Open the file
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $file.FullName
#Set label for page loop so we can exit when match found
:PageLoop for ($page = 1; $page -le $reader.NumberOfPages; $page++) {
$lines = [char[]]$reader.GetPageContent($page) -join "" -split "`n"
foreach ($line in $lines) {
#Loop through all folder names to look for matches in the file
foreach ($folder in $destinationFolders) {
#Look for a Regex match for the folder name
if ($line -match $folder.Name) {
#Set flag for match to true
$foundMatch = $true
#Get folder info
$destPath = $folder.FullName
$destFolder = $folder.Name
#Break page loop, but stay in file loop
break :PageLoop
}
} #for each folder in destination folders
} #for each line in lines
}#for each page in pdf
#Close the opened file
$reader.Close()
if ($foundMatch -eq $true) {
"Match found for {0} in file {0}" -f $folder.Name, $file
Copy-Item -Source $file.FullName -Destination $destPath
}
else {
"No matches for any folder names in file {0}" -f $file
}
} #for each file in files
but my code everytime give me message
PS C:\Users\administrator.DRI> .\extpdf-ext.ps1
GAC Version Location
--- ------- --------
False v2.0.50727 C:\Scripts\PdfToText\itextsharp.dll
No matches for any folder names in file 1.pdf
No matches for any folder names in file 2.pdf
No matches for any folder names in file Document1.pdf
where is error? where i must change code