MattNicholas
asked on
Folder copy script
Hi,
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?
Thanks
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?
Thanks
ASKER
Thanks mani,
Is should this be run from Powershell?
Is should this be run from Powershell?
For power shell you could do this
$folders = get-childitem C:\test | where{$_.name -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
$folders = get-childitem C:\test | where{$_.name -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
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.
Chris
ASKER
Hi Chris,
So what script would I need to use from robocopy to do this? Would i use the one Mani has given me?
Thanks
So what script would I need to use from robocopy to do this? Would i use the one Mani has given me?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
solved
Try this:
cp -r c:\sourcefolder\*-2008* d:\destinationfolder\
This will copy only 2008 folders