复制列表中除文件以外的所有内容

时间:2017-11-04 07:14:09

标签: powershell powershell-v2.0 powershell-v3.0

我正在尝试递归地将所有文件从a:\复制到b:\除了那些元数据存在于a:\list.txt中的文件。 list.txt模式为LastWriteTimeYYYY-MM-DD HH:MM:SS,size,.fileextension,例如:

2001-01-31 23:59:59,12345,.doc
2001-01-31 23:59:59,12345,.txt
2001-01-31 23:59:00,456,.csv

...因此,a:\目录树中与这些元数据匹配的任何和所有文件都应复制。

我似乎在使用Where-Object时遇到问题,以排除list.txt上的项目,但复制其他内容:

$Source = "C:\a"
$Target = "C:\b"

$List = Import-Csv list.txt -Header LastWriteTime,Size,Name

$Hash = @{}
ForEach ($Row in $List){
    $Key = ("{0},{1},.{2}" -F $Row.LastWriteTime,$Row.Size,$Row.Name.Split('.')[-1].ToLower())
    IF (!($Hash[$Key])) {$Hash.Add($Key,$Row.Name)}
}
$Hash | Format-Table -Auto

Get-Childitem -Path $Source -Recurse -File | Where-Object {$Hash -eq $Hash[$Key]}| ForEach-Object {$Key = ("{0},{1},{2}" -F ($_.LastWriteTime).ToString('yyyy-MM-dd HH:mm:ss'),$_.Length,$_.Extension.ToLower())
    #$Key
    If ($Hash[$Key]){
        $Destination = $_.FullName -Replace "^$([RegEx]::Escape($Source))","$Target"
        If (!(Test-Path (Split-Path $Destination))){MD (Split-Path $Destination)|Out-Null}
        $_ | Copy-Item -Destination $Destination
    }
}

1 个答案:

答案 0 :(得分:0)

我建议您简化代码:

 <div class="modalData" id="talentData">
                    <div class="modalOverlay"></div>
                    <div class="contentData">


                        <div class="dataContainer">
                            <div class="gr-2 gallery">

                                <div><img ng-src="{{product.images}}"></div>

                            </div>

                            <div class="gr-2 biodata">

                            </div>
                        </div>


                        <a href="#" id="closeData">X</a>

                    </div>
                </div>