Copying files to directory different than in other dir

Hi All,

I'm looking for part of script, I would like to use robocopy. I have to optimize script and I have following concept:
I would like to copy only unique files from DirA to DirC. I have archive from last 7 days with files previously copied from A to C in DirB.
I would like to copy files from A to C from last three days, but only ones that are new or modified from those in DirB.
I cannot compare files from DirA to those already copied to archive DirB by name because some of the files in A can be modified, so in that case dir on DirB and /XF swith in robocopy cannot be used.

Can you provide me idea how to do it?

Regards,
Adam Nowak
MCDPLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
Have you considered using /maxage:3 that would exclude files over 3 days old.... BUT I think I understand this as:

DirA: FILE1, FILE2, FILE3, FILE4
DirB: FILE4, FILE3
DirC: Wants FILE2, FILE1?

So it seems you want a list of the files that have changed in the last 3 days in DirA then see if they are the same in DirB and if not copy them to DirC?  Are any of the names likely to be different, in which case no chance!

In which case does this show you the righ files for starters... this does not do copying, just lists the files that WOULD be copied based on changed in last 3 days.

We could use that output to copy files unless I have got your requirements wrong?

Steve

robocopy d:\dira d:\dirb /maxage:3 /l /njh /njs /fp

Steve
0
MCDPLAuthor Commented:
Thanks for posting.
I'm aware of /maxage switch, but the trick is that in this example:
DirA: FILE1, FILE2, FILE3, FILE4
DirB: FILE4, FILE3
DirC: FILE1, FILE2, and FILE3 in case this file in DirA has been modified

So DirC should have files from DirA, that is new or modified compared to files from DirB.
I'm not sure if it's clear enough.
After copying files to DirC those files will be compressed and moved to archive (DirB). So this folder will have new version of FILE3.

Regards,
Adam Nowak
0
Steve KnightIT ConsultancyCommented:
Ok so doing the options I suggested above does it show you the right files?

robocopy d:\dira d:\dirb /maxage:3 /l /njh /njs /fp

That output can be read and used to do an actual copy command for instance.

Are we talking handful or 100's, 1000's of files etc. btw?

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

MCDPLAuthor Commented:
It seems that it's exactly what I'm looking for.
It's around 20-30 files, not more.

Thanks!

Regards,
Adam Nowak
0
Steve KnightIT ConsultancyCommented:
OK that will only SHOW you the files though.  If you want the copy automated too we can do along the lines of this using a for loop to read the filenames and run an XCOPY /D to copy the file if it is newer:

@Echo off
set DirA="D:\dira"
Set DirB="D:\dirb"
Set DirC="D:\dirc"
for /f "tokens=3 skip=1" %%A in ('robocopy %dira% %dirb% /maxage:3 /l /njh /njs /fp') do (
  echo Copying %%~A
  XCOPY /D "%%~A" %dirc%
)

Steve
0
MCDPLAuthor Commented:
I know, but key for me was the way to list differences between two dirs.
With that I will make the rest, but I had no idea how to list differences between two dirs.

Thanks for that.

Regards,
Adam Nowak
0
Steve KnightIT ConsultancyCommented:
No problem, glad to help anyway, ask more if needed.

Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.