This code:
$output = "copyright-$tif"
& $tool "-c lzw" "c:\copyright pages\copyright.tif" $tif.FullName $output
results in a command a bit like this:
tiffcp.exe -c lzw "1.tif" "c:\2.tif" "copyright-c:\2.tif"
The problem is that "copyright-$tif"
is putting the full file path in, and that makes the output a nonsense filename.
Try:
$tool = 'c:\tiff-3.8.2-1-bin\bin\tiffcp.exe'
$tifs = Get-ChildItem .\*.tif
foreach ($tif in $tifs)
{
if ($tif -like '*copyright*')
{
write "File already has copyright notice $tif"
} else {
write "Processing $tif"
$output = "copyright-$($tif.Name)"
& $tool -c lzw "c:\copyright pages\copyright.tif" $tif.FullName $output
Move-Item $tif C:\backup
}
}
Comments:
Get-ChildItem can find *.tif directly, without getting all files and using where, so I changed that.
Used string interpolation for `"Processing $tif" and similar
I think if ($tif -match 'copyright')
or if ($tif.Name.Contains("copyright"))
feel nicer, but why not filter those out earlier, when you get-childitem?
EDIT example code filtering out the already copyrighted ones:
e.g.
$tool = 'c:\tiff-3.8.2-1-bin\bin\tiffcp.exe'
$tifs = (gci .\*.tif | ?{ $_.Name -notmatch "copyright" })
foreach ($tif in $tifs) {
write "Processing $tif"
& $tool -c lzw "c:\copyright pages\copyright.tif" "$tif" "copyright-$($tif.Name)"
Move-Item $tif C:\backup
}