Folder copy script


I have a large amount of folders i need to copy to a new folder. Half the folders have -2008 folders and the other half have -2009

Is there a script able to just copy just the -2008 folders to the new location and leave the -2009 ones where they are?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aman SubhanOracle Database AdministratorCommented:
Quite simple command:
Try this:

cp -r c:\sourcefolder\*-2008* d:\destinationfolder\

This will copy only 2008 folders
MattNicholasAuthor Commented:
Thanks mani,

Is should this be run from Powershell?
For power shell you could do this

$folders = get-childitem C:\test | where{$ -match "-2008" -and $_.psiscontainer -eq "True"}
Foreach($Folder in $folders){
Move-item $folder.fullname C:\Test1

I dont know if you have just one level or multiple levels.

You could also use robocopy with the exclusion switch to include only -2008 folders
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Chris DentPowerShell DeveloperCommented:

I would go for RoboCopy because if your structure is large you may run into problems with Path length when using PowerShell.

PowerShell is a .NET language and uses System.IO to handle file listing (as well as other file operations). For security reasons paths are limited to a maximum of 259 or 260 characters, any longer and the script will error.

RoboCopy on the other hand will allow paths up to 32000 characters long and should have no problem with any kind of copy.

MattNicholasAuthor Commented:
Hi Chris,

So what script would I need to use from robocopy to do this? Would i use the one Mani has given me?

Chris DentPowerShell DeveloperCommented:
Robocopy has a lot of options, the basic should be:

robocopy *-2008 SomeDestination

What do you want to do beyond that? Take a look at "robocopy /?". I normally use Robocopy for permanent moves, so I end up with:

robocopy *-2008 SomeDestination /COPYALL /MIR /R:0 /W:0

I suggest you use this first to make sure it's capturing the things you want:

robocopy *-2008 SomeDestination /COPYALL /MIR /R:0 /W:0 /L /FP

The /L option makes it log only, it makes no changes. /FP makes it log the full path for each file instead of just the name.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MattNicholasAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.