2

I cant figure out what I am doing wrong with this command and would like another set of eyes to point it out.

I want to copy the directory structure but not the files the structure contains.

Copy-Item -recurse -exclude *.* -path \\server1\z$\backups\  -destination \\server2\z$\ -Verbose

The command runs but it copys files despite telling it not to copy files. How do i copy the directory tree and not the files?

3 Answers 3

1

Try this.

copy-item -path "\\server1\z$\backups\" -Destination "\\server2\z$\" -Filter {$_.PSIsContainer -eq $True} -recurse

1
  • BTW, I think the reason your original command didn't work is because the -Include and -Exclude parameters are applied to any wildcards in the -Path parameter. Your original command had no wildcards, so the -Exclude parameter did nothing in your case.
    – pk.
    May 9, 2012 at 16:23
0
robocopy /e /XF *.*

Sorry, that didn't really answer your question. Maybe try something like this:

ForEach($folder in Get-ChildItem -Recurse \\server1\z$\backups\ | ? { $_.PSIsContainer }) { Copy-Item -Path $folder -Destination \\server2\z$\$folder }

That above PS script probably needs some tweaking -- I did not really test it. But the concept is there.

0

This is what I came up with. You can take out the "mkdir" command to test before running it.

$src =  "c:\temp"
$dest = "c:\test"

$dirs = dir -Recurse $src | Where {$_.psIsContainer -eq $true}
foreach( $name in $dirs ) {
    $tmp = $name.fullname.Replace($name.Root,$dest + "\")
    $tmp
    mkdir $tmp
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .