diegomirner
asked on
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
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
ASKER
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
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
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?
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?
ASKER
Yes perfect
well .. something like this should do it then:
function CopyDirectory(source,desti nation:str ing):boole an;
var r,s:TSearchRec;
begin
result:=true;
if source[length(source)]<>'\ ' then
source:=source+'\';
if destination[length(destina tion)]<>'\ ' then
destination:=destination+' \';
if findfirst(source+'*.*',faA nyFile {$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.Nam e, destination+r.Name)
else
begin
if fileexists(destination+r.n ame) then
begin
assert(findfirst(destinati on+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.n ame);
findclose(s);
end;
result:= result and CopyFile(pansichar(source+ r.Name),pa nsichar(de stination+ r.name),fa lse);
end;
end;
until findnext(r)<>0;
findclose(r);
end;
end;
modified this code: https://www.experts-exchange.com/questions/21833058/Delete-a-folder-recursivly.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
function CopyDirectory(source,desti
var r,s:TSearchRec;
begin
result:=true;
if source[length(source)]<>'\
source:=source+'\';
if destination[length(destina
destination:=destination+'
if findfirst(source+'*.*',faA
-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.Nam
else
begin
if fileexists(destination+r.n
begin
assert(findfirst(destinati
if r.Time>s.Time then//if source (r) is newer then destination(s)
deletefile(destination+r.n
findclose(s);
end;
result:= result and CopyFile(pansichar(source+
end;
end;
until findnext(r)<>0;
findclose(r);
end;
end;
modified this code: https://www.experts-exchange.com/questions/21833058/Delete-a-folder-recursivly.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
ASKER
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
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok , thanks an im realy sorry
no problem :) it is a good idea to alwasy double check;)
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.