如何复制文件夹,同时排除PowerShell中的一些子文件夹

时间:2018-01-04 15:42:28

标签: powershell

我是PowerShell的新手,我正在尝试将没有子文件夹的文件夹复制到另一个文件夹。我在下面提供了我的代码。希望这是有道理的。

$from = 'C:\erp\github\bliss_'
$to = 'C:\erp\websites\bitesize'
$ExcludeFolders = @(".git","DHTMLX","mflasite","nbproject",".gitignore")

Get-ChildItem -Path $from -Recurse -Exclude $ExcludeFolders |  Copy-Item  $_.fullname -Destination $from -Force -Exclude $ExcludeFolders

1 个答案:

答案 0 :(得分:0)

因此-Exclude符合Path的条件。您需要输入可识别的模式:

$ExcludeFolders = @(
    '*\.git\*'
    '*\DHTMLX\*'
    '*\mflasite\*'
    '*\nbproject\*'
    '*\.gitignore'
)
-Exclude <String[]>
    Specifies, as a string array, an item or items that this cmdlet excludes in
    the operation. The value of this parameter qualifies the Path parameter. Enter
    a path element or pattern, such as *.txt. Wildcards are permitted.

    Required?                    false
    Position?                    named
    Default value                None
    Accept pipeline input?       False
    Accept wildcard characters?  false