简体   繁体   中英

How to copy a folder whilst excluding some sub folders in powershell

I am very new to PowerShell and i am trying to copy a folder without some sub folders to a different folder. I have included my code below. Hope this makes sense.

$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

So -Exclude qualifies the Path . You need to enter a pattern that it can identify:

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM