Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Make Backup File(s) via Send to


  • Please log in to reply
No replies to this topic
Venia Legendi
  • Members
  • 35 posts
  • Last active: Apr 04 2011 08:36 PM
  • Joined: 27 May 2005
Hi,

I often need backup from files.

So I wrote a script which hooks itself in the "Send to" menu at the first start without parameters. Then selecting some files and choosing Send to > Make Backup(s) in the context menu does the job for me. It first generates a file with YYYY-MM-DD added, if this exists it tries YYY-MM-DD@HHMMSS.

For convinience it should be compiled.
; AutoHotkey Script
#singleinstance force
#include Debug.ahk
IfLess, 0, 1
If A_IsCompiled
{
	SendToDir = %UserProfile%\SendTo
	IfNotExist, %SendToDir%
	{
		MsgBox, 16,, %SendToDir% not found (Perhaps you've moved it?)
		ExitApp
	}	
	StringTrimRight, ScriptName, A_ScriptName, 4
	IfExist, %SendToDir%\%ScriptName%.lnk
	{
		FileDelete, %SendToDir%\%ScriptName%.lnk
		MsgBox, 64,, Shortcut %SendToDir%\%ScriptName%.lnk deleted
	}
	else
	{
		FileCreateShortcut, %A_ScriptFullPath%, %SendToDir%\%ScriptName%.lnk
			, %A_ScriptDir%,,Make Backup Files with current date,,%A_ScriptFullPath%
		MsgBox, 64,, Shortcut %SendToDir%\%ScriptName%.lnk generated
	}	
	ExitApp
}
else
{
	MsgBox, 16,, Compile me ("Send to" a script is possible, but complicated).
	ExitApp
}
tooltip =
Loop, %0% 
{
	DBG(A_Index "-" %A_Index%)
	ifnotexist, % %A_Index% 
	{
		tooltip := tooltip %A_Index% "does not exist?`n"
		DBG(" not found?")
		continue
	}
	SplitPath, %A_Index%,, BckDir, BckExt, BckName
	BckDatei := BckDir "\" BckName " " A_YYYY "-" A_MM "-" A_DD "." BckExt
	ifexist, %BckDatei%
	{
		DBG(" -> " BckDatei " exists")
		BckDatei := BckDir "\" BckName " " A_YYYY "-" A_MM "-" A_DD "@" A_Hour A_Min A_Sec "." BckExt
		ifexist, %BckDatei%
		{
			DBG(" -> " BckDatei " also exists")
			tooltip = %tooltip%! %BckDatei% exist, nothing done`n
			continue
		}
	}	
	FileCopy, % %A_Index%, %BckDatei%
	If ErrorLevel
	{
		tooltip = %tooltip%! %BckDatei% could not copy!`n
		DBG(" -> " BckDatei " could not copy")
	}
	else
	{
		tooltip = %tooltip%* %BckDatei% generated`n
		DBG(" -> " BckDatei " generated")
	}
}
CoordMode, ToolTip, Screen
ToolTip, %tooltip%Processed %0% file(s),0,0
Sleep, 2000

and the debug.ahk
DBG := True
DBG(Meldung)
{
	Global DBG
	If (!DBG) 
		Return
	OutputDebug, (%A_ScriptName%) %Meldung%
}