• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

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
0
MCDPL
Asked:
MCDPL
  • 4
  • 3
1 Solution
 
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Featured Post

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now