Link to home
Start Free TrialLog in
Avatar of MCDPL
MCDPL

asked on

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
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of MCDPL
MCDPL

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MCDPL

ASKER

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

Thanks!

Regards,
Adam Nowak
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
Avatar of MCDPL

ASKER

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
No problem, glad to help anyway, ask more if needed.

Steve