Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##########################################################################################################################################
- ## Notepad like backup : A basic no frills backup solution for SublimeText 3, all files will be ##
- ## renamed with the addition of a time stamp and .bak and then saved to a location, No extra folders are created. ##
- ## ##
- ## instructions to use: ##
- ## Make sure to replace the _user_backup_path with your own file location you wish to save all your backups. ##
- ## Place this file in : C:/Users/UserName/AppData/Roaming/Sublime Text 3/Packages - if on windows.. or ##
- ## use goto in Sublime Preferences/Browse Packages.. ##
- ## it [i]SHOULD[i] run automagicaly in the background every time you save ##
- ## if not, To make sure this runs every time you save will need to run this command once in the console: ##
- ## window.run_command("NotepadBackUp") ##
- ## ##
- import sublime
- import sublime_plugin
- import sys
- import os
- import time
- import shutil
- class NotepadBackUpCommand(sublime_plugin.EventListener):
- def on_post_save(self, view):
- _file = view.file_name()
- _filename = ( os.path.basename( _file ) )
- _filetime = time.strftime( "%Y_%m_%d_%H%M")
- _filetime = ( _filetime[0:(len(_filetime) -1)]) ## limits to the 10 minute range eg wont write 00 - 60 but will write 0 - 6 versions..
- _user_backup_path = "C:/Users/YourPathHereEtc .."
- _filepath_time_bakup = ( _user_backup_path + '/' + _filename + '.' + _filetime + '.bak' )
- ExternalPathExists = os.path.exists( os.path.dirname( _filepath_time_bakup ) )
- if ExternalPathExists is True:
- shutil.copyfile( _file , _filepath_time_bakup )
- sys.stdout.write('# ' + 'Creating Backup:- ' + _filepath_time_bakup + ' #\n')
- else:
- sys.stdout.write('# ' + 'ERROR (path does not exist??!) :- ' + _filepath_time_bakup + ' #\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement