Sign in to follow this  
Followers 0
JohnOne

Nimps Folder Backup

1 post in this topic

#1 ·  Posted (edited)

"Nimps" is a regional slang word, which means easy or simple or basic and such.

I made a quick little script the other day to backup the visual studio project folder I was actively working on.

Thought I'd generalise it for use with the current active windows explorer folder.

When this script is running, and you hit "Ctrl and Shift and b", if a folder is open in windows explorer, it will copy the contents of it to your desired location ($GENERAL_BACKUP_FOLDER) including subfolders and its files and folders (so beware on deep directories)

If you have command line version of 7zip (7za.exe) you can choose to compress the folder rather than just copy it ($ZIP_FOLDER = True), or both I suppose.

Think that's all.

Reading the code should tell you anything else.

Oh, success or failure is indicated by a high or low frequency Beep().

#include <AutoItConstants.au3>
#include <String.au3>

HotKeySet("^+b", _Backup) ; ctrl and shift and b
HotKeySet("!+b", _Exit) ; alt and shift and b

Global Const $GENERAL_BACKUP_FOLDER = @ScriptDir & "Backup\"
Global Const $ZIP_FOLDER = False
Global Const $PATH_TO_7ZA = "D:\7za.exe"

While 3
    Sleep(300)
WEnd

; High frequency beep if successful
; Low frequency beep if failed
Func _Backup()
    Local $FOLDER_TO_BACKUP = ""
    Local $BACKUP_FOLDER = ""
    Local $CURRENT_BACKUP_FOLDER
    Local $WIN_TITLE = WinGetTitle("[Active]")
    Local $WIN_TEXT = WinGetText("[Active]")

    ; If text of window has no address, it is not a windows explorer
    If StringInStr($WIN_TEXT, "Address: ") Then
        Local $ACTIVE_EXPLORER_ADDRESS = _StringBetween($WIN_TEXT, "Address: ", @LF)
        If Not IsArray($ACTIVE_EXPLORER_ADDRESS) Then
            Beep(400, 150)
            Return @ScriptLineNumber
        EndIf
        $FOLDER_TO_BACKUP = $ACTIVE_EXPLORER_ADDRESS[0]
    Else
        Return MsgBox(0, "Info", "The active window is not explorer")
    EndIf

    ; Check to see if root drive is backup source
    If StringRight($FOLDER_TO_BACKUP, 2) = ":\" Then
        $Answer = MsgBox(4, "Warning", "You are about to attempt to backup a whole disk" & @CRLF & "Are you sure?")
        If $Answer <> 6 Then Return
    EndIf

    ; Date and time to append to backup zip file or folder
    $APPEND = "_" & @YEAR & "_" & @MON & "_" & @MDAY & "_" & @HOUR & "_" & @MIN & "_" & @SEC
    Local $CURRENT_BACKUP_FOLDER = $GENERAL_BACKUP_FOLDER & $WIN_TITLE & $APPEND

    ; Zip to backup folder and return, 7za.exe required
    If $ZIP_FOLDER Then

        ; Buile command for 7za
        $command = $PATH_TO_7ZA & ' a ' & '"' & $GENERAL_BACKUP_FOLDER & $WIN_TITLE & $APPEND & '"' & '.zip ' & '"' & $FOLDER_TO_BACKUP & '"'
        $pid = Run($command, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        While ProcessExists($pid)
            Sleep(10)
        WEnd
        $out = StdoutRead($pid)

        ; Indicate if successfull
        If StringInStr($out, "Everything is Ok") Then
            Beep(700, 200)
            Return
        EndIf
        Beep(400, 200)
        Return
    EndIf

    ; Copy folder and beep when complete, no 7zip needed.
    Local $RTN = DirCopy($FOLDER_TO_BACKUP, $CURRENT_BACKUP_FOLDER, 1) ? Beep(700, 500) : Beep(400, 500)

EndFunc   ;==>_Backup

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Marc
      By Marc
      Profiler - yet another backup script for Firefox and Thunderbird profiles
      It automatically detects the last recently used profile directories of Firefox and Thunderbird (installed versions, no portables).
      Clicking the Backup-Button creates a complete Backup of the found profiles with a timestamp.
      Restore deletes the according profile dir and extracts the content of the selected archive into the profile directory.
      Uses Winrar as compression tool, but feel free to change it to your needs
      Best regards
      Marc

      Profiler.au3
    • Vivi
      By Vivi
      hey guys,
       
      is there a way to post into the "Usenet" with autoit ?
       
      I didn't found any resources about it online.
    • Wicked_Caty
      By Wicked_Caty
      I wanted to have a few lines that copy the whole registry into a file. I know that there is RegRead, but I don't want to type every single key into my code...
      Any way of doing this easily? Filetype doesn't matter, as long as it isn't encrypted. A batch or exe would be okay, if it's in the same location on every PC. Doing this without admin permissions would be awesome too
      Thanks
    • wakillon
      By wakillon
      TinyBackupBox : Do a Backup of folders you want to a local/external drive/directory by using Robocopy.

      A Big Thank to Yashield for TVExplorer.au3 and WinApiEx.au3

      Includes needed : >TVExplorer.au3 and >WinApiEx.au3



      * Left Treeview :

      Check all folders Checkboxes you want to backup.
      Hold Shift key when clicking a first child Checkbox will check all other child Checkboxes.
      A right click on a parent item will uncheck all his child Checkboxes.

      * Right Treeview :

      A left click for select Backup Directory.
      A right click menu on an item for create a new sub-folder which you can give the name you want.
      This new sub-folder will be created and added as child item of the item you have right clicked.

      * Start Button :

      A Click on Start Button will start backup normally.
      Hold Shift key when clicking it will start backup on Idle Mode.
      Idle Mode is used for start or resume backup after a period of user inactivity (that you can set by tray menu)
      and will pause current backup if not idle.

      * Stop Button :

      A click on Stop Button will Pause backup, and any changes will affect the backup when resume it.
      You can resume a current backup by Re-clicking Start Button.
      Hold Shift key when clicking Stop Button will totally Cancel current backup.
      In Idle mode Stop Button is inactive until you Hold Shift key and click for Cancel current backup.

      * Refresh Button :

      A Click will refresh both treeviews and set them to the previous selections you have done.
      Hold Shift key when clicking it will refresh both treeview and set them to the root.

      * Tray Menu :

      By Default Robocopy copy only new files,
      so i add the possibility to
      _ delete previous existing dir.
      _ delete destination files and dirs that no longer exists in source.
      _ Preserve all Attributes.
      _ Show Robocopy Console window.
      _ Set Idle Time Delay.
      _ Open Backup Dir.

      Update of 2011-12-21
      Previous downloads : 103
       
      source and executable are available in the Download Section

      minimalist but handy !
      Hope you like it !

      And do not forget to create backup periodically !
    • wakillon
      By wakillon
      Do a backup of a folders list