Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell:将文件和文件夹复制到新目标,但忽略某些文件和文件夹_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

Powershell:将文件和文件夹复制到新目标,但忽略某些文件和文件夹

Powershell:将文件和文件夹复制到新目标,但忽略某些文件和文件夹,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,我对Powershell非常陌生,为我们的开发过程编写了一个脚本,将文件和文件夹从(比如)文件夹1复制到文件夹2,但忽略一些文件和文件夹 我无法使下面的脚本工作 #Exclude list of files and folders to be copied $excludeFiles = [System.Collections.ArrayList]('*.exe', '*.config', '*.targets', '*.rsp') $excludeFolders = [System.Colle

我对Powershell非常陌生,为我们的开发过程编写了一个脚本,将文件和文件夹从(比如)文件夹1复制到文件夹2,但忽略一些文件和文件夹

我无法使下面的脚本工作

#Exclude list of files and folders to be copied
$excludeFiles = [System.Collections.ArrayList]('*.exe', '*.config', '*.targets', '*.rsp')
$excludeFolders = [System.Collections.ArrayList]('CustomConfiguration', 'abc')

function CopyFilesToFolder ($fromFolder, $toFolder, $ignoreExcludes) {
    $foldersRegex = "($($($excludeFolders.ToArray()) -join "|"))";
    $filesRegex = "($($($excludeFiles.ToArray()) -join "|"))";

    Get-ChildItem -Path $fromFolder -Recurse |
        Where-Object {($_ -ne $null) -and (($ignoreExcludes -eq $false -and $_.fullname -notmatch $foldersRegex) -or ($ignoreExcludes -eq $true)) } |
        Where-Object { ($_ -ne $null) -and (($ignoreExcludes -eq $false -and $_.fullname -notmatch $filesRegex) -or ($ignoreExcludes -eq $true)) } | 
        Copy-Item -Force -Destination {
        if ($_.GetType() -eq [System.IO.FileInfo]) {
            Join-Path $toFolder $_.FullName.Substring($fromFolder.length)
        } 
        else {
            Join-Path $toFolder $_.Parent.FullName.Substring($fromFolder.length)
        }
    }
}
p.S:另外,我如何组合到excludeFiles和excludeFolders列表


多谢各位

Get-ChildItem
-Exclude
-Include
作为参数。你可以直接利用它。