I already spent hours on this problem, but I didn’t succeed in finding a working solution.
Here is my problem description:
I’m a newbie in powershell, somehow I read books and made a required code but it is showing errors which i cant sort out. What the code does it fetches images from a folder and places copy of each image according to the closest available ratio (0.67,1.33,1.2) compared to the image aspect ratio in the folders(0.67,1.33,1.2) to some other location.
My code looks more or less like this:
[System.Reflection.Assembly]::LoadFile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll")
#index of minimum value
$p = [array]::IndexOf($ratioarray, $minimum)
if($p -eq 0){
$dst_dir = $des_dir+"powershell\0.4"
if (!(Test-Path $dst_dir)) {
# create it
[void](new-item $dst_dir -itemType directory)
}
Copy-Item $src_dir$image $dst_dir
}
if($p -eq 1){
$dst_dir = $des_dir+"powershell\0.5"
if (!(Test-Path $dst_dir)) {
# create it
[void](new-item $dst_dir -itemType directory)
}
Copy-Item $src_dir$image $dst_dir
}
if($p -eq 2){
$dst_dir = $des_dir+"powershell\0.67"
if (!(Test-Path $dst_dir)) {
# create it
[void](new-item $dst_dir -itemType directory)
}
Copy-Item $src_dir$image $dst_dir
}
"$name|$width|$height|$ratioroundoff|$dst_dir" >> $datafile
$imageFile.Dispose()
}
It gives error:
Copy-Item : The given path's format is not supported.
At C:\Users\busy\desktop\copyflow.ps1:71 char:10
+ Copy-Item <<<< $src_dir$image $dst_dir
+ CategoryInfo : InvalidOperation: (C:\Users\busy\D...ics2\jack.jpg:String) [Copy-Item], NotSupportedException
+ FullyQualifiedErrorId : ItemExistsNotSupportedError,Microsoft.PowerShell.Commands.CopyItemCommand
The problem seems to be with file names.
$images = Get-ChildItem -Recurse $src_dir -Include *.jpgwill populate a collection withFileInfoobjects that already have absolute file names present. No path mangling is needed.Instead of
Try something like
If it still doesn’t work, print output to console and check what is wrong. Like so,