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

Syncronize directories

Hi Experts

i have to  2 directories ( fedora 4) , each of one haves all most  the same files and directories  , but i need jest one of them with the newest version of all files and subdirectories , what i should do ?

Thanks
0
diegomirner
Asked:
diegomirner
  • 5
  • 4
1 Solution
 
2266180Commented:
well .. which one do you want?

if you know the name of the file that you want, then just find it within the directories (findfirst/findnext) and compare the dates (comparedate or something similar from dateutils)
if you don't know the name of the file then you nees some constraints: you do the same findfirstfindnext but then you apply your restrictions (like size, attributes, etc)

if none of the above, then you need to give an actual example, since I don't quite undestand your request.
0
 
diegomirnerAuthor Commented:
Ok, sorry i will explain you better:

Directory A: files and folder (40 GB) lets say 33040 files and folder + files wich are not in Directory B

Directory B : all most the same of Directory A but with newers version off the same files + new files

i need to feet all in jest one directory overwrite to the new version in the case of have the same files this folders , but the problem its i have to be really carefully because all this files are in the file server and im concern to take all the resources if i run a big process to do it , i will have a lot of user coming to kill me , jejej


thanksssssss
0
 
2266180Commented:
well ... let's see if I got it correctly:

copy over from B to A all files adn directories and overwrite only the files which in A are older than in B.
the result will be the one you want. right or wrong?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
diegomirnerAuthor Commented:
Yes perfect
0
 
2266180Commented:
well .. something like this should do it then:

function CopyDirectory(source,destination:string):boolean;
var r,s:TSearchRec;
begin
  result:=true;
  if source[length(source)]<>'\' then
    source:=source+'\';
  if destination[length(destination)]<>'\' then
    destination:=destination+'\';
  if findfirst(source+'*.*',faAnyFile {$WARNINGS OFF}
                                  -faVolumeID-faSymLink {$WARNINGS ON}
               ,r)=0 then
  begin
    repeat
      if (r.name<>'.') and (r.name<>'..') then
      begin
        if r.Attr and faDirectory = faDirectory then result:= result and copyDirectory(source+r.Name, destination+r.Name)
                                                else
        begin
          if fileexists(destination+r.name) then
          begin
            assert(findfirst(destination+r.name,faAnyFile,s)=0);// if this fails, big problem
            if r.Time>s.Time then//if source (r) is newer then destination(s)
              deletefile(destination+r.name);
            findclose(s);
          end;
          result:= result and CopyFile(pansichar(source+r.Name),pansichar(destination+r.name),false);
        end;
      end;
    until findnext(r)<>0;
    findclose(r);
  end;
end;


modified this code: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21833058.html (accepted answer)

you should test this prior to using it as I am at work and don't have the time to set up a similar evironment.
The line I am not exactly sure about is this one:
            if r.Time>s.Time then//if source (r) is newer then destination(s)
since the times are integers and not tdatetimes; I do hope the comparison is done correctly.

if it is not correct, the replace it with a call to:
FileDateToDateTime
and then use
function CompareDate(const A, B: TDateTime): TValueRelationship;
to compare the dates
0
 
diegomirnerAuthor Commented:
Thanks for your answer , but i dont unthertand all this  , i was lookng mach easy for me like using rsync , becouse all that you jest write its like chines forme .
Thanks
0
 
2266180Commented:
well .. you posted on delphi programming so I gave you a solution in delphi. maybe you posted in the wrong forum? you could ask in community support to be moved if it's the case.
0
 
diegomirnerAuthor Commented:
ok , thanks an im realy sorry
0
 
2266180Commented:
no problem :) it is a good idea to alwasy double check;)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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