Notepad++ – How to Set New File Names

notepadplugins

Is there a way to have Notepad++ generate new file names with the current date?

Like this:
YYYY_MM_DD_new1.txt
or similar.
Currently it just names them: new1, new2, etc.

Date in the file name will work great with autosave, there will be no name conflicts after NPP restart.

All I want is a way to store sessions between restarts. I want to autosave even the unnamed files.

Thanks.

Best Answer

I just did this using the Python Script plugin for NPP...

notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
def my_callback(args):
    if notepad.getBufferFilename(args["bufferID"]) == "new  1":
        fmt = '%Y%m%d%H%M%S'
        d = datetime.datetime.now()
        d_string = d.strftime(fmt)
        notepad.saveAs('X:\\Documents\\Notepad++_autosave\\%s.txt' % d_string)
notepad.callback(my_callback, [NOTIFICATION.BUFFERACTIVATED])

With the above code, as soon as I type Ctrl+N, the new file is created and saved instantly with the name formatted as defined in 'fmt' above. The path for the file to be saved is defined above as well; change it to suit your environment.

Related Question