Question

I want to develop a script that copies,verifies, and then deletes from one network location to another (files over x days old).

Here is my algorithm:

Recursively traverse a network location ($movePath)
for all files $_.LastWriteTime >= x days | forEach {
   xcopy or robocopy $FileName = $_.FullName.Replace($movePath, $newPath)
   if (the files where written correctly) {
     (delete) Remove-Item $Filename from $movePath
   }

Can I combine the xcopy /v (verify) with robocopy?

Was it helpful?

Solution

Do you want to maintain the subfolder structure (i.e. files from a subfolder in the source go into the same subfolder in the destination)? If so, this should suffice:

$src = 'D:\source\folder'
$dst = '\\server\share'
$age = 10  # days

robocopy $src $dst /e /move /minage:$age

robocopy can handle verification (done automatically) and deletion by itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top