1
The following Powershell script is supposed to process all designated images INSIDE the specified Rootfolder. Some of the renamed output images are generated OUTSIDE the Rootfolder. Any Powershell gurus have any idea why? How can I output files only in the Rootfolder and not OUTSIDE the Rootfolder?
# This script requires ImageMagick
# Configuration
# Enter the full path of the folder that contains the images
$Rootfolder = "C:\temp\rktest"
$Recursive=$true
# Change these if necessary
$fileExtensions = "*.png"
$fileNameSuffix = "_resized" # the text to be appended to the output filename to indicate that it has been modified
$files = $null;
$fileCount = 0
# Check if the root folder is a valid folder. If not, try again.
if ((Test-Path $RootFolder -PathType 'Container') -eq $false) {
Write-Host "'$RootFolder' doesn't seem to be a valid folder. Please try again" -ForegroundColor Red
break
}
# Get all image files in the folder
if ($Recursive) {
$files = gci $RootFolder -Filter $fileExtensions -File -Recurse
}
# If there are no image files found, write out a message and quit
if ($files.Count -lt 1) {
Write-Host "No image files with extension '$fileExtensions' were found in the folder '$RootFolder'" -ForegroundColor Red
break
}
# Loop through each of the files and process it
foreach ($image in $files) {
$newFilename = $image.DirectoryName + " " + $image.BaseName + $fileNameSuffix + $image.Extension
$imageFullname = $image.FullName
write-host "Processing image: $imageFullname" -ForegroundColor Green
#This line contains the ImageMagick commands
& convert.exe $image.FullName -resize 50% $newFilename
$fileCount++
}
Write-Host "$fileCount images processed" -ForegroundColor Yellow
What do you mean with
OUTSIDE
? – LotPings – 2018-06-02T05:46:10.480You're not showing the complete script. – Gerard H. Pille – 2018-06-02T06:29:42.040
Gerald - I am showing the complete script - what do you see is missing? – bobkush – 2018-06-02T19:46:30.470
I see break commands. They are meant to exit a loop but are not inside a loop. I see a variable $Recursive that is never set. – Gerard H. Pille – 2018-06-03T00:37:35.990