Save Backup of Unnamed File - Work in Progress



  • Hi,

    Windows Update keeps eating my files… it’d be amazing if autosave worked on files that weren’t named yet.

    E.g. you start a new Notepad… start writing. and autosave grabs it for say unnamed1.txt

    Is this possible?



  • @NN123616 said in Save Backup of Unnamed File - Work in Progress:

    E.g. you start a new Notepad… start writing. and autosave grabs it for say unnamed1.txt
    Is this possible?

    I suggest you start your reading here. This is a FAQ post that gives you lots of information about backup strategy and what Notepad++ offers, both built-in and with plugins.

    If after that you still have questions ask away, but you need to read that first.

    Terry



  • @NN123616

    you start a new Notepad… start writing. and autosave grabs it for say unnamed1.txt

    Is this possible?

    I don’t know much about it, but maybe the AutoSave plugin will do that. I’ve never actually used that plugin.
    I think the TakeNotes plugin can do such a thing, although it has been a while since I’ve used it.

    If I were doing it for myself, I’d use the PythonScript plugin and a little script, maybe like this:

    # -*- coding: utf-8 -*-
    
    from Npp import *
    import os
    import time
    
    try:
        AUF__callback_npp_BUFFERACTIVATED
    except NameError:
        def AUF__callback_npp_BUFFERACTIVATED(args):
            if editor.getTextLength() == 0:
                if not os.path.isfile(notepad.getCurrentFilename()):
                    notepad.saveAs(os.environ['TEMP'] + os.sep + time.strftime("%Y%m%d-%H%M%S", time.localtime()) + '.txt')
        notepad.callback(AUF__callback_npp_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED])
    

    This will, instead of doing “unnamed1.txt”, do a timestamp for a filename; example:

    3b364c94-49ff-400d-a05c-49f19d8e91f1-image.png

    This demo puts the file in the folder where the TEMP environment variable points, but that’s easily customized to something else.


Log in to reply