Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

Converting the FileSystemObject's CopyFolder Method


Windows PowerShell


Definition: Copies one or more folders to a specified location.

CopyFolder


The CopyFolder method recursively copies all files, subfolders, files within the subfolders, and so on from the source folder to the destination folder. PowerShell uses the Copy-Item cmdlet to copy folders, but it works a little differently. Here are some examples.

This command copies the C:\temp folder and all its contents to the C:\old folder:


Copy-Item c:\temp c:\old


However, if the C:\temp folder contains subfolders, the above command simply creates a new folder under C:\old named temp, with none of the contents copied. To recursively copy everything from C:\temp to C:\old, you need to use a wildcard, like this:


Copy-Item c:\temp\* c:\old


C:\old must exist for the preceding command to work. If C:\old does not exist, the preceding command will create it and copy all the files from C:\temp to the new C:\old folder, but none of the subfolders within C:\temp will be copied.

Yes, we know, it’s a little confusing. Play around with it, copying folders with and without subfolders. We’d say you’ll get the hang of it, but we’re still a little confused ourselves.


See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.