Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I more than 200K folders that I need to move from one network location to another network location. I want to do it with Robocopy.
I need help with 2 things

1. I want to move folders starting with string '19'
2. I want to move folders created before 2019 year.

What I have tried:

robocopy \\netwroksourcepath\path\19* \\netwrokdestinationpath\path\ /E /MOVE /MT
Posted
Updated 16-Jun-20 2:22am
Comments
Richard MacCutchan 16-Jun-20 3:34am    
And? What is the question?

1 solution

robocopy | Microsoft Docs[^]

There is no support for wildcards in the source directory. You'll need to use a for loop to issue a separate robocopy command for each matching folder.
FOR /D %G In ("\\networksourcepath\path\19*") DO robocopy %G \\networkdestinationpath\path\%~nG /E /MOVE /MT
(In a batch file, you'd need to double-up the % characters.)

I can't see an easy way to copy folders based on their creation date in a batch file. You might need to use Powershell for that.
PowerShell
$MaxDate = Get-Date -Date "2019-01-01"
Get-ChildItem "\\networksourcepath\path" -Attributes Directory | Where-Object CreationTime -lt $MaxDate | ForEach-Object -Process { 
    $destination = "\\networkdestinationpath\path\$($_Item.Name)"
    robocopy $_.FullName $destination /E /MOVE /MT
}
 
Share this answer
 
Comments
Maciej Los 16-Jun-20 8:47am    
5ed!
webmail123 19-Jun-20 16:37pm    
Great. Thanks for the reply. About moving folders, how can we move folders older than 45 days?
Richard Deeming 22-Jun-20 11:04am    
Try:
$Now = Get-Date
$MaxDate = $Now.Date.AddDays(-45)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900