-1

我已经在这个问题上花费了几个小时,但我没有成功找到一个可行的解决方案。

这是我的问题描述:

我是powershell的新手,不知何故我读了书并编写了所需的代码,但它显示了我无法解决的错误。代码的作用是从文件夹中获取图像,并根据与文件夹中的图像纵横比(0.67、1.33、1.2)相比最接近的可用比率(0.67、1.33、1.2)将每个图像的副本放置到其他位置。

我的代码看起来或多或少是这样的:

[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() 
 }

它给出了错误:

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 
4

1 回答 1

1

The problem seems to be with file names. $images = Get-ChildItem -Recurse $src_dir -Include *.jpg will populate a collection with FileInfo objects that already have absolute file names present. No path mangling is needed.

Instead of

Copy-Item $src_dir$image $dst_dir

Try something like

Copy-Item $image.FullName $dst_dir

If it still doesn't work, print output to console and check what is wrong. Like so,

write-host $("Copy-Item {0} {1}" -f $image.FullName, $dst_dir)
Copy-Item -whatif $image.FullName $dst_dir
于 2012-10-11T07:07:40.370 回答