Copy-Item和Join-Path创建文件夹而不是文件

时间:2017-06-28 16:45:45

标签: powershell

我遇到一个问题,即在目的地中组合Copy-Item和使用Join-Path会导致文件夹创建文件夹&文件夹名称中的扩展名,而不是复制原始文件。

我尝试了以下代码的几种变体。此外,我尝试使用{} for Destination使其成为一个脚本块,但最终抛出一个错误,说没有输入,因此无法进行评估。我也尝试将-ItemType设置为file,但是会抛出相同的异常错误。如果有帮助,我的PS版本是v2.0.1.1。

假设所有变量都已实例化并且工作正常,我已经单独测试了每个变量

Get-ChildItem -Path $Src -Recurse -Force | Where-Object {$_.Name -notcontains "Archive"}| 
ForEach-Object {
    if(!$_.PSIsContainer){
    $DateStr = $_.BaseName.Substring(0,2)+'/'+$_.BaseName.Substring(3,2)+'/'+$_.BaseName.Substring(6,4)  
    $FileDate = get-date $DateStr
    If ( $FileDate -ge $Date ) {
        $ParentOjbect = $_.Directory 
        $Parent = $ParentOjbect.Name
        Copy-Item -Path (Join-Path -Path $Src -ChildPath '\*' ) -Destination (Join-Path $Dst '{0} {1}' -f $Parent,$_.Name) 

    }}
}

0 个答案:

没有答案
相关问题