首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell -从ForEach-Object返回/传输对象

Powershell -从ForEach-Object返回/传输对象
EN

Stack Overflow用户
提问于 2015-10-20 22:18:29
回答 1查看 174关注 0票数 1

我当前可以传输文件..但不知何故,内容被遗漏了。我认为该对象没有正确返回,但无法弄清楚。

代码语言:javascript
复制
$folder1 = "<external server>"
$folder2 = "<local path>"

# Get all files under $folder1, filter out directories
$firstFolder = Get-JFSChildItem $folder1 | Where-Object { -not $_.PsIsContainer }

    $firstFolder | ForEach-Object {
    # Check if the file, from $folder1, exists with the same path under $folder2
    If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
    {
        $fileSuffix = $_.FullName.TrimStart($folder1)
        Write-Host "$fileSuffix is only in folder1"
        Receive-JFSItem $fileSuffix -destination $folder2
    }

}

错误:接收-JFSItem:没有这样的文件;没有这样的文件。

错误: Receive-JFSItem <<<< $fileSuffix -destination $folder2

EN

回答 1

Stack Overflow用户

发布于 2015-10-20 22:27:58

您错误地使用了TrimStartTrimStart接受从参数中裁剪的一组符号,并且您希望将文件夹名称裁剪为从其开头开始的精确字符串。您应该将$_.fullname中的$folder1替换为空字符串。

代码语言:javascript
复制
If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
{
    $fileSuffix = $_.FullName.Replace($folder1,"")
    Write-Host "$fileSuffix is only in folder1"
    Receive-JFSItem $fileSuffix -destination $folder2
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33239180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档