Hi all, does anyone have a good robocopy script to move files older than a specific date using the /MINAGE switch and also the /MINLAD?

I have to move a truck load of files older that 7 years or not accessed in the last 3 years.

Can’t quite figure the best way to approach this.

8 Spice ups
robocopy c:\source d:\old /minage:20070625 /e /move
robocopy c:\source d:\old /minlad:20110625 /e /move

Will something like this work for you?

3 Spice ups

Kind of, Krizz. I wanted to try to make it happen in a single move. That’s where I’m stuck. How to have robocopy process on both minage and minlad at the same time.

I’m afraid that if you use both quantifiers in single command they will be treated in conjunction, not disjunction. That’s why you need to do it twice.

3 Spice ups

You can put the both lines in a batch file or a powershell file and then run just that one script and both robocopys will run. Or were you looking for something that will copy files that are older than 7 years AND have not been touched in 3 years.

1 Spice up

That will only process files though… If this is project based operation (i.e. a bunch of files in a different project folders) then the question is has anything in this folder been changed in the past 3 yrs if not move it to the archive folder. Otherwise you will be moving most of the project files but not all of them and create more headache. I don’t have a good solution for that but maybe someone else does. (I know I could use a script with that kind of logic to it)

1 Spice up

Why do you need them on single command? Is there any particular reason?

txheed you’re on the right track.

It probably is more an AND statement.

minage <=7 years AND minlat <=3 years

This isn’t robocopy but here’s some powershell that should work for you. I threw copy-item onto the end of it for you. Just note, copy-item does not show any output, so if you would like to see what’s going on just get rid of the pipe to copy-item for the test run.

Instead of copy… | move-item -destination “c:\test” -force

You can also change to .AddYears or .AddMonths if you prefer!

Get-ChildItem –Path “d:\data” –Recurse | Where-Object {$_.LastAccessTime –le (Get-Date).AddDays(-9) -and $_.CreationTime -le (Get-Date).AddDays(-9)} | copy-item -destination "c:\test" -recurse -Force
2 Spice ups

so this is what I went with but the weird thing is that no files are being copied, only directories. I’ve confirmed several GB of files which are earlier than the specified date.

robocopy E: S: /E /B /A+:A /MOVE /COPYALL /DCOPY:T /XD [EXCLUSIONS] /MINLAD:20070630 /R:3 /W:5 /V /LOG+:C:\robocopy.log.txt /TEE

Ideas?

Isn’t it because you’ve used /MINLAD:20070630 instead of /MINAGE:20070630? Perhaps all files have been accessed after 20070630.

I checked a few files and there are plenty that are showing last access time prior to that date. It’s kind of weird. I’ll work it out at some point. :slight_smile:

The problem is you don’t want to move younger files. Indeed, you can achieve the same result as OR operator by using AND operator and negation, bu there is no negation for robocopy params as far as I know.

That’s what I’m seeing too.

There has to be some way to achieve this goal though :slight_smile:

I’d do test copying (not moving) on this particular folder only.

This might help get closer with powershell Archived MSDN and TechNet Blogs | Microsoft Learn it still doesnt solve look in entire project folder to see if anything has been edited since and to archive path if unmodified. … This will give a list of the folders: Archived MSDN and TechNet Blogs | Microsoft Learn Now to merge the two together ?

txheed I’m thinking I would need to stay away from robocopy and us PS, as well.

Goals to achieve:

Move all files over 7 years and no longer in use.
Move all files of certain type no used in 3 years.
Retain all security attributes.
Set archive bit after copy.
Purge source file/directory.

My PS is limited. Who feels like writing this? :slight_smile:

How are you determining no longer in use, last accessed ? There’s going to be multiple lines in order to accomplish. Problem with ps is that remove-item and move-item don’t output, so what you’ll have to do is capture the get-childitem and output that as your list of files that have been touched, and add transcript for any errors that may come about.

That’s correct.

so what you’ll have to do is capture the get-childitem and output that as your list of files that have been touched, and add transcript for any errors that may come about.

That’s a good approach. Any chance you would be able to write such a script?

I’ll see what I can put together tomorrow when I get to work.

1 Spice up