Cedeq Community Forum
Keyboard Shortcut - Backing Up a File - Printable Version

+- Cedeq Community Forum (https://forum.cedeq.com)
+-- Forum: General (https://forum.cedeq.com/forumdisplay.php?fid=1)
+--- Forum: Keyboard shortcuts with AutoHotkey code (https://forum.cedeq.com/forumdisplay.php?fid=4)
+--- Thread: Keyboard Shortcut - Backing Up a File (/showthread.php?tid=11)



Keyboard Shortcut - Backing Up a File - denilama - 02-22-2018

If you’re constantly modifying an important file, you know you should be backing it up regularly, just in case. Starting File Explorer, locating the right folder, selecting the right file, copying the file, and then pasting it can be enough to make you want to skip this important task.

With the AutoHotkey script below, creating a shortcut in ShortKeeper will make backing up a file fast and easy. If something goes wrong with your working file, the backup will save you time and money.

Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
FolderName := "c:\folder"
FileNameWithoutExtension := "filename"
FileNameExtension := "ext"
 
IfNotExist, %FolderName%\%FileNameWithoutExtension%.%FileNameExtension%
{
  MsgBox, The file to back up does not exist:`n%FolderName%\%FileNameWithoutExtension%.%FileNameExtension%
}
else

  IfNotExist, %FolderName%\bak
    FileCreateDir, %FolderName%\bak
  FormatTime, CurrentDateTime,, yyyy-MM-dd_hh-mm
  FileCopy, %FolderName%\%FileNameWithoutExtension%.%FileNameExtension%, %FolderName%\bak\%FileNameWithoutExtension%_%CurrentDateTime%.%FileNameExtension%, 1
  if ErrorLevel
    MsgBox Unable to bak up the file %FileNameWithoutExtension%.%FileNameExtension%.
}

At line #1: "c:\folder" must be replaced with the actual name of the folder that contains the file that is to be backed up (do not include “\” at the end; do not remove quotation marks). 

At line #2: "filename" must be replaced with the actual name of the file that is to be backed up (do not include file extension; do not remove quotation marks).

At line #3: "ext" must be replaced with the actual extension of the file name (do not remove quotation marks).

This script will create (or use an existing) "\bak" folder to back up the file. It will include a date & time stamp in the backup filename.