0

I've got a question. I want to do the following thing with PowerShell. Copy everything to a new directory except the folders named "56789" and "56789121". I tried GCI with the -Exclude option but it's not working as I want it.

You can find a visual representation of how I want to copy the things below:

C:\DATA
+---2
|   +---56789
|   +---Archived2001
|   |   |   66.txt
|   |   |
|   |   \---New folder
|   \---Archived2002
\---4
    |   33 - Copy.txt
    |   33.txt
    |
    +---56789121
    +---Archived2005
    \---Archived2008
            33 - Copy.txt
C:\MOVED
+---2
|   +---Archived2001
|   |   |   66.txt
|   |   |
|   |   \---New folder
|   \---Archived2002
\---4
    |   33 - Copy.txt
    |   33.txt
    |
    +---Archived2005
    \---Archived2008
            33 - Copy.txt

Until now I've got this but it's not working.

$from = 'c:\data'
$to = 'c:\moved'
$exclude = 'C:\data\*\[0-9]\'
Get-ChildItem -Path $from -r | ? {
    $_.PsIsContainer -and $_.FullName -notmatch '$exclude'
} | Copy-Item -Destination $to -WhatIf
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

0 Answers0