Следующий скрипт Powershell должен обрабатывать все указанные изображения ВНУТРИ указанной корневой папки. Некоторые из переименованных выходных изображений создаются вне корневой папки. Любые гуру Powershell имеют представление, почему? Как я могу выводить файлы только в корневую папку, а не вне корневой папки?
# 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
 