Jump to content



Photo

Synchronize the content of 2 directories


  • Please log in to reply
18 replies to this topic

#1 Apzo

Apzo

    Adventurer

  • Active Members
  • PipPip
  • 117 posts

Posted 24 July 2006 - 05:08 PM

Hello !

I searched a way to easily backup my au3 scripts from work to home and vice versa.
I found no (simple) equivalent to rsync on windows.

So this is my attempt.
It works "as is" and lets you choose friendly the source and destination directories, or with command line args.
In case of command line mode, remember to enclose spaced paths with "

Example : rsync "c:\documents and settings\me\my_folder" e:\
where e:\ is your USB storage key for example :)

Rsync checks if a newer version of a file exists on both sides, and copy the newest at the right place.
Rsync doesn't keep an history of your files as SVN would, so in case a file has been modified in the source AND destination, the newest will stay and the older will be overwritten.

I hope this will help :whistle:

Apzo.

[EDIT] Script updated, thanks to DMEE :)

Attached Files


Edited by Apzo, 26 June 2008 - 10:38 AM.






#2 gamerman2360

gamerman2360

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 505 posts

Posted 24 July 2006 - 10:06 PM

Or you could start a new briefcase. I guess with this you don't have to drag and drop each file. :whistle:

#3 Apzo

Apzo

    Adventurer

  • Active Members
  • PipPip
  • 117 posts

Posted 25 July 2006 - 08:51 AM

No drag and drop needed, just select the 2 folders to synchonize and it's done :)
Usefull when you work on a project at home and at work : just rsync your project on an USB key.

I'm working on a net version using FTP, so you can allways get the latests files up to date anywhere.
I'm thinking about a file history system, too.
You would be able to set the number of backups for your files, and retrieve up to version-X if needed.

No extra soft to install, just a standalone .exe : AU3 rocks :whistle:

Apzo.

#4 FitzChivalry

FitzChivalry

    Wayfarer

  • Active Members
  • Pip
  • 50 posts

Posted 29 January 2007 - 09:02 PM

Hey Apzo, this is awesome. I work on my scripts at home and at work and it has always been a pain to figure out which ones are up to date. I'll start using this! thanks a bunch!

#5 krigaren

krigaren

    Seeker

  • Active Members
  • 6 posts

Posted 30 January 2007 - 11:40 PM

Very useful script.

Thanks for sharing.

/ K :)

#6 DMEE

DMEE

    Wayfarer

  • Active Members
  • Pip
  • 85 posts

Posted 26 June 2008 - 07:54 AM

The script is really useful, but one small bug fix in your script would be changing:

If StringRight($PathTo, 1) = "\" Then     $PathFrom = StringTrimRight($PathTo, 1) EndIf

In the beginning there was nothing and then even that exploded - anonymous

#7 Apzo

Apzo

    Adventurer

  • Active Members
  • PipPip
  • 117 posts

Posted 26 June 2008 - 10:42 AM

You're right DMEE :)
I've updated the script.

Thanks !!
Apzo.

#8 laidback01

laidback01

    Seeker

  • Active Members
  • 48 posts

Posted 18 July 2008 - 10:56 PM

There is Microsoft's SyncToy. It works rather well for syncing files.

#9 kjcdude

kjcdude

    Adventurer

  • Active Members
  • PipPip
  • 142 posts

Posted 12 September 2008 - 02:55 AM

Perfect, just what i was looking for.

#10 rogdog

rogdog

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 12 September 2008 - 02:50 PM

Hello !

I searched a way to easily backup my au3 scripts from work to home and vice versa.
I found no (simple) equivalent to rsync on windows.


'DeltaCopy' is a simple rsync tool for windows. Did you try that ?

#11 Bart74

Bart74

    Seeker

  • New Members
  • 1 posts

Posted 22 May 2009 - 10:17 AM

Thanks for this excellent script.

I have modified it to my own needs. I wanted to sync ppt files to a working directory, also the ones that do not exist in the source should be deleted. Also it should not copy any ppt file that is opened for edit.

AutoIt         
Func Sync($from, $to, $ext, $withdelete) ; A modification from: ; <a href='http://www.autoitscript.com/forum/index.php?showtopic=29715' class='bbc_url' title=''>http://www.autoitscript.com/forum/index.php?showtopic=29715</a>     ; Building the logical source directory     Local $returnVal = False     Local $FilesFrom = FileFindFirstFile($from & "*." & $ext)     While 1         Local $file = FileFindNextFile($FilesFrom)         If @error Then ExitLoop         ; Building the full path to source and destination file (or directory)         Local $filename = FileGetLongName($from & $file)         Local $tofilename = FileGetLongName($to & $file)                 ; Getting the mod. time of source and dest file...         Local $fromtime = FileGetTime($filename, 0, 1)         Local $totime = FileGetTime($tofilename, 0, 1)                 ; In case the destination file does not exists, $fromtime is always greater than $totime         If $fromtime > $totime and not(FileLocked ($filename)) Then             FileCopy($filename, $tofilename, 9)             $returnVal = True         EndIf     WEnd     ; Proper close of the file list     FileClose($FilesFrom)         ; If True, we should delete the files in the destination dir that do not exist in the source anymore     If $withdelete Then         Local $FilesTo = FileFindFirstFile($from & "*." & $ext)         While 1             $file = FileFindFirstFile($FilesTo)             If @error Then ExitLoop             ; Building the full path to source and destination file (or directory)             Local $filename = FileGetLongName($from & $file)             Local $tofilename = FileGetLongName($to & $file)                         ;if the file in the from-dir does not exist, we should delete it in the dest-dir             if not(FileExists ($fileName)) then                 FileDelete($tofileName)                 $returnVal = True             EndIf         WEnd         FileClose($FilesTo)     EndIf     ; Return whether some copy/delete action took place     return $returnVal EndFunc Func FileLocked ($fileName)     ; Checks if a file is locked     local $hFile = fileopen($fileName,1)     Return $hFile <> -1     fileclose ($hFile) EndFunc

Edited by Bart74, 22 May 2009 - 10:19 AM.


#12 DrLove

DrLove

    Seeker

  • New Members
  • 2 posts

Posted 24 May 2009 - 12:04 PM

Works great!

Is it possible to add a progressbar to the script?!

Thanx

#13 Apzo

Apzo

    Adventurer

  • Active Members
  • PipPip
  • 117 posts

Posted 25 May 2009 - 09:37 AM

Is it possible to add a progressbar to the script?!

Everything is possible.
BUT the _RSync func is recursive so it's a bit crappy.

At the begenning, add :
Global $FileCount
Global $FileProg


Before the 2 calls to func _RSync() add :
Local $NbFilesFrom = DirGetSize($PathFrom, 1)
Local $NbFilesTo = DirGetSize($PathTo, 1)

If $NbFilesFrom[1] >= $NbFilesTo[1] Then ; Number of processed files = max($NbFilesFrom, $NbFilesTo) * 2, for 2 rsyncs are done
$FileCount = $NbFilesFrom[1] * 2
Else
$FileCount = $NbFilesTo[1] * 2
EndIf

$FileProg = $FileCount

ProgressOn("Rsync", "Synchronizing...") ; Let's go for a progress bar


And just after, ProgressOff() of course.

In the _RSync func, just before the WEnd, add :
ProgressSet($FileProg*100/$FileCount, "Remaining : " & $FileProg)
$FileProg -= 1


And you're done :)

Apzo.

#14 DrLove

DrLove

    Seeker

  • New Members
  • 2 posts

Posted 25 May 2009 - 10:08 AM

Everything is possible.
BUT the _RSync func is recursive so it's a bit crappy.

At the begenning, add :
Global $FileCount
Global $FileProg


Before the 2 calls to func _RSync() add :
Local $NbFilesFrom = DirGetSize($PathFrom, 1)
Local $NbFilesTo = DirGetSize($PathTo, 1)

If $NbFilesFrom[1] >= $NbFilesTo[1] Then ; Number of processed files = max($NbFilesFrom, $NbFilesTo) * 2, for 2 rsyncs are done
$FileCount = $NbFilesFrom[1] * 2
Else
$FileCount = $NbFilesTo[1] * 2
EndIf

$FileProg = $FileCount

ProgressOn("Rsync", "Synchronizing...") ; Let's go for a progress bar


And just after, ProgressOff() of course.

In the _RSync func, just before the WEnd, add :
ProgressSet($FileProg*100/$FileCount, "Remaining : " & $FileProg)
$FileProg -= 1


And you're done :)

Apzo.

Thanx, I'll try that.

#15 sliceofpie

sliceofpie

    Wayfarer

  • Active Members
  • Pip
  • 62 posts

Posted 13 August 2010 - 12:53 AM

Everything is possible.
BUT the _RSync func is recursive so it's a bit crappy.

At the begenning, add :
Global $FileCount
Global $FileProg


Before the 2 calls to func _RSync() add :
Local $NbFilesFrom = DirGetSize($PathFrom, 1)
Local $NbFilesTo = DirGetSize($PathTo, 1)

If $NbFilesFrom[1] >= $NbFilesTo[1] Then ; Number of processed files = max($NbFilesFrom, $NbFilesTo) * 2, for 2 rsyncs are done
$FileCount = $NbFilesFrom[1] * 2
Else
$FileCount = $NbFilesTo[1] * 2
EndIf

$FileProg = $FileCount

ProgressOn("Rsync", "Synchronizing...") ; Let's go for a progress bar


And just after, ProgressOff() of course.

In the _RSync func, just before the WEnd, add :
ProgressSet($FileProg*100/$FileCount, "Remaining : " & $FileProg)
$FileProg -= 1


And you're done :)

Apzo.

This works but the status bar goes backwards. ;) It shows a 100% done, then goes down to zero.

#16 wehr

wehr

    Seeker

  • Active Members
  • 11 posts

Posted 15 November 2010 - 05:12 PM

I was wondering if there is a way to make this synchonize a local directory with a folder on a server via ftp. But i can't think of any ways to insert the FTP folder correctly. Any suggestions?

#17 ZacUSNYR

ZacUSNYR

    Prodigy

  • Active Members
  • PipPipPip
  • 194 posts

Posted 15 November 2010 - 06:40 PM

If you want to use a commmand line utility - check out Robocopy - it came with a Microsoft Resource Kit awhile back but can be found online. It offers a 'mirror' file copy option.

#18 storme

storme

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 754 posts

Posted 16 November 2010 - 08:05 AM

If you want to use a commmand line utility - check out Robocopy - it came with a Microsoft Resource Kit awhile back but can be found online. It offers a 'mirror' file copy option.


If your interested in Robocopy you coudl check out my Robocopy function. it makes life a lot easier.
http://www.autoitscript.com/forum/index.php?app=forums&module=forums&section=findpost&pid=843922

Good luck
John Morrison

#19 Apzo

Apzo

    Adventurer

  • Active Members
  • PipPip
  • 117 posts

Posted 16 November 2010 - 12:54 PM

Another way to sync dirs is to use a GNU port for windows of the well-known unix command 'cp'.

Check the -u option :
cp --help
...
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing

I use it twice : source -> destination then destination -> source.

Apzo.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users