比较对象文件名到变量供以后参考

时间:2016-01-22 23:54:10

标签: loops powershell compare subdirectory copy-item

我是PowerShell的新手,但我决心按下学习曲线,需要一些额外的帮助。

我正在使用Compare-Object比较子目录之间的文件,它可以工作并返回所有差异的列表。

我需要将差异(文件名)填充到数组/变量(?)中,然后引用文件名以将文件复制到指定位置。

[string] $CopyFromPath = "C:\folder"
[string] $TargetCopyPath = "D:\folder"


Compare-Object -ReferenceObject $SourceFileSet -DifferenceObject ($TargetParentPath + $child) |
    Select @{
        n = "$($child.ToUpper()) (Missing data in $TargetCopyPath)"
        e = {$_.InputObject}
    } | ft


foreach($f in $MissingFile) {
    Copy-Item -Path ($CopyFromPath + "\" + $MissingFile) -Destination $TargetCopyPath
}

它可能非常简单,我的做法可能有点过分,但任何意见都会受到高度赞赏。

谢谢!

0 个答案:

没有答案
相关问题