AutoHotkey Community

It is currently May 26th, 2012, 3:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: December 31st, 2008, 4:07 pm 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
I have looked for a while to find a small utility to easily backup selected folders on my usb drive without the hassle of ensuring it is mapped as the same drive letter on all machines.

This script uses a free utility called Dsynchronize, which can be downloaded from http://dimio.altervista.org/eng/.

The original inspiration came from this post: http://www.autohotkey.com/forum/viewtopic.php?t=15889&highlight=xxcopy+gui

Installer (browse to root of usb drive for install location)

Download sync.ahk

Download sync.ico

No frills version: Download dsynchronize.ahk

This script uses A_ScriptDir and A_MyDocuments to ensure predictable results whatever machine your usb drive is connected to.

To use this script copy the ahk code and dysnchronize.exe to the root directory of your usb drive. (dsynchronize.ini is not required). It will ask for which folders you want to be backed up. The backup copy is saved to a folder USB_Backup in your My Documents folder.

Once you have nominated the folders to be backed up, just select yes to use the last settings as you move from machine to machine, and the script will do the housekeeping of setting the correct drive letter for you.

Current limitations:

Only can backup from root level directories (subdirectories included) up to 99 folders
Adds some clutter to your tray with two icons

To do:

Maybe add a toolbar gui to dsynchronize.exe and remove tray menu

Edit:

Code has been revised, now it does what it was supposed to do :oops:

Code:
;This script requires DSynchronize by Dimio
; Download Dsynchronize from http://dimio.altervista.org/eng/
;AHK forum IfNotExist, ce : http://www.autohotkey.com/forum/viewtopic.php?t=15889&highlight=xxcopy+gui


#NoEnv

;check for Dsynchronize.exe in USB root directory (required)
IfNotExist, %ThisDrive%DSynchronize.exe, {
MsgBox, 48,USB Synchronize,Copy Dsynchronize.exe to the root directory
ExitApp
}

;find usb drive letter
StringLeft, DriveLetter,A_ScriptDir,2
ThisDrive = %DriveLetter%`\

;define backup folder
IfNotExist, %A_MyDocuments%USB_backup
FileCreateDir, %A_MyDocuments%USB_backup
PCFolder = %A_MyDocuments%`\USB_backup

;decide whether to use last settings
IfExist, %ThisDrive%ahkDsync.ini, {
MsgBox, 4, USB Synchronize, Use Last Settings?
IfMsgBox, Yes
Gosub,  UpdateDriveLetter
IfMsgBox, No
Gosub, SelectFolders
}Else{
Gosub, SelectFolders
}
Return


SelectFolders:

FileDelete, %ThisDrive%ahkDsync.ini

Gui, Add, ListView, r20 w300, Directories
Gui, Add, Button, ,Ok
Gui, Add, Button, xp+50,Cancel

; List directory names from usb drive and put them into the ListView:
Loop, %A_ScriptDir%\*, 2 ; 2 = look for dirs only
{
Stringtrimleft,Folder,A_LoopFileLongPath,3
   LV_Add("", Folder)
}
LV_ModifyCol()  ; Auto-size each column to fit its contents.
Gui, Show
return

ButtonOk:
RowNumber = 0  ; This causes the first loop iteration to start the search at the top of the list.
FolderNo = 0

Loop
{
   RowNumber := LV_GetNext(RowNumber)  ; Resume the search at the row after that found by the previous iteration.
   if not RowNumber  ; The above returned zero, so there are no more selected rows.
      break
     
   LV_GetText(USBFolder, RowNumber)
   KeyFolderNo := IniKey(FolderNo)
   IniWrite, +%ThisDrive%%USBFolder%,ahkDsync.ini,Settings,Origine%KeyFolderNo%
   IniWrite, +%PCFolder%\%USBFolder%,ahkDsync.ini,Settings,Destinazione%KeyFolderNo%
   IniWrite,%USBFolder%,ahkDsync.ini,LastFolders,%FolderNo% ; changed 20090204
   
   FolderNo++
   
}
Gui, Destroy

IniWrite,True,ahkDsync.ini,Settings,SyncBidirezionale
IniWrite,False,ahkDsync.ini,Settings,RealTimeSync
IniWrite,False,ahkDsync.ini,Settings,SaveOnExit ;check for effect on operations
IniWrite,True,ahkDsync.ini,Settings,SeNonEsisteCreaLaDestinazione
IniWrite,False,ahkDsync.ini,Settings,SpegniAlTermine
IniWrite, %FolderNo%,ahkDsync.ini,LastFolders,NumberofFolders

Run, DSynchronize.exe /START /MINIMIZED /ahkDsync.ini

return

GuiClose:
ButtonCancel:
ExitApp

UpdateDriveLetter:
;delete existing mydocs references in ini file

IniRead, Folders,ahkDsync.ini,LastFolders,NumberofFolders
IniDelete, ahkDsync.ini,Settings,Destinazione0000
loop
{
If A_Index > %Folders%-1
Break
KeyFolderNo := IniKey(A_Index)
IniDelete, ahkDsync.ini,Settings,Destinazione%KeyFolderNo%
}

; add new references to mydocs
IniRead, PrevUSBFolder,ahkDsync.ini,LastFolders,0
IniWrite, +%PCFolder%\%PrevUSBFolder%,ahkDsync.ini,Settings,Destinazione0000


loop
{
If A_Index > %Folders%-1 ; 20090204 check output of ini file/dsynchronize
Break
KeyFolderNo := IniKey(A_Index)
LastFolderNo = %A_Index%
IniRead, PrevUSBFolder,ahkDsync.ini,LastFolders,%LastFolderNo%
IniWrite, +%PCFolder%\%PrevUSBFolder%,ahkDsync.ini,Settings,Destinazione%KeyFolderNo%
}
;remap source driveletter

StringLeft, MyDocDrvLtr, A_MyDocuments, 1
FileRead,OldIniFile, ahkDsync.ini
OldIniFile := RegExReplace(OldIniFile, "[^" . MyDocDrvLtr . "]:", DriveLetter, count)
FileDelete, %ThisDrive%ahkDsync.ini
FileAppend, %OldIniFile%, ahkDsync.ini

Run, DSynchronize.exe /START /MINIMIZED /ahkDsync.ini
Return

;FUNCTIONS
IniKey(LoopCount)
{
  KeyFolderNo = 000%LoopCount%
  StringLen, KeyLength, KeyFolderNo
  If (KeyLength >= 5) {
  KeyFolderNo = 00%LoopCount%
  }
  Return KeyFolderNo
}



Last edited by supergrass on May 31st, 2009, 2:28 pm, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2008, 7:02 pm 
Offline

Joined: February 17th, 2008, 5:01 pm
Posts: 303
Very helpful.. Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Original script edited
PostPosted: February 4th, 2009, 11:18 am 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
I have been using this for a while now and realised there were some major bugs with it. :shock:


It is now doing what I want: when I move between pcs, it will back up any changes to files on the usb drive root folders to a folder called USB_Backup under the local My Documents mapping, and swap the usb drive letter to suit.

The updated code is in the original post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: new update
PostPosted: March 6th, 2009, 12:48 pm 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
I have updated the script.

It now has a custom menu and automatic setup of autoplay.

The original post has been updated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2009, 9:45 am 
Hey,

One question..

Do you need Admin rights to do this? I'm thinking about doing it at college so I can backup my work, but to install AutoHotkey I'll need to be Admin I presume, as limited users can't install anything.


Report this post
Top
  
Reply with quote  
 Post subject: compile the script
PostPosted: March 7th, 2009, 12:04 pm 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
Chris 4,

If you compile the script, you won't have to install autohotkey.

I have previously installed autohotkey to my documents folder so you could also try that.

I have uploaded the icon I use also.

Supergrass


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2009, 7:02 am 
Offline

Joined: March 7th, 2009, 9:46 am
Posts: 3
Ah, I didn't know about compiling a script. Thanks :)

Thanks.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group