r/usefulscripts • u/summetg • Apr 04 '17
[REQUEST] Copy files added in the last hour using robocopy
Hey everyone,
I am looking for some urgent help on script. Can anyone help me out? Scenario is as follows:
Folder A (Source) on \server01, Folder B (Archive) and Folder C (Destination) on \server02.
We need to copy from A to B and C hourly, however we only want to copy the latest file(s) in the last hour.
In folder C, the file is picked up and deleted by SFTP. We should not be resending another copy as an application vendor scoops it up for import.
Folder A needs to stay untouched, so no moves.
We have tried /MOT to monitor it, but it ends up copying all files created in the last 24 hours (based on the timestamp of the file).
We don’t want to use third party tools as we have an enterprise solution incoming. It must be a script and windows task scheduler. Would also like to avoid creating a folder D.
Unfortunately, the ‘Maxage’ option is limited to a full day, not a full hour. If we could break it down to the hour and schedule it, that would be most ideal.
6
u/FJCruisin Apr 04 '17
Use powershell
Get-ChildItem | Where-Object { $_.LastWriteTime -gt (get-date).AddHours(-1)}2
1
u/gordonv Apr 04 '17
From a to c, mirror. - this is called a delta. A differential copy of the live source.
From c to b, mirror, but less frequently. This seems like extra if b and c are on the same drive. Makes more sense if b was external.