How to recover a Notepad++ lost session

4

I had my Notepad++ with at least 50 opened files on it, organizing all my work.

I left the computer as always hibernating overnight and surprise, this morning all was gone.

An error message popped up when maximizing Notepad++, something along a file not being able to be opened.

I accepted the error and Notepad++ had no files on it.

After rebooting nothing changed, and in the backups folder I only found standalone old dirty files that I worked on a long time ago...

Any thoughts on how to recover my precious working session?

Thanks,

Peanuts

Posted 2018-07-27T15:42:11.980

Reputation: 141

I searched for the session.xml file on C:\Users\user.user-PC\AppData\Roaming\Notepad++ but it got "reset" and isn't showing all the old opened tabs. I went to [right click] > Preferences > Old Versions but there's no old version available. On Windows Temp folder there're no "session" files, on "n++" or "npp" or "notepad" files :( – Peanuts – 2018-07-27T16:41:58.427

Possible duplicate of Is there any way to recover unsaved notepad++ docs?

– JonathanDavidArndt – 2018-08-21T13:02:23.447

Answers

3

You cannot, but you can secure against happening this again.

This is possible if you have your cloud path set in Preferences:

enter image description here

After the breakdown, immediately turn off syncing with the cloud and restore the original file from there. If your cloud has file versioning, then it is simpler: just retrieve the older version of the sessions.xml.

This also works for all other setting files, see the link above for details.


Also be sure that you updated to at least Notepad++ 7.5.9.

In its list of fixed bugs, there is

  1. Fix possible file corruption during backup or power loss or other abnormal N++ termination.

So yes, this has been addressed in October 2018.

miroxlav

Posted 2018-07-27T15:42:11.980

Reputation: 9 376

2I have Notepad++ 7.5.9 and this just happened to me: my computer lost power (UPS failed!) and when I opened Notepad++ again I see a clean session. In the "backup" folder I see copies of the unnamed files, but I see no way to restore all the named files I was working on – Joe Pineda – 2018-11-22T16:18:32.013

@JoePineda – hm, thanks for sharing. So maybe the cloud backup is really the next option to try? Even if the backup may be delayed, it can be still better to recover somewhat older tab set then start with blank one. – miroxlav – 2018-11-23T09:00:17.060

@miroxlav I ended up installing "recuva" as suggested in another answer to the same data loss by Notepad++ - it worked like a charm, recovering all the files I was working at the moment, and even the session file (which I manually substituted). I only needed to point recuva to a shared folder on another network machine to leave the files at. I was dissappointed by Notepad++, though, this destroying of user info is totally unacceptable - they should be using SQLite or something like that to have ACID changes in the files they're touching, database-style – Joe Pineda – 2018-11-26T23:46:41.787

1

Thanks to Joe Pineda for his comment on the backup folder. After losing my crashed session, I saw that in this folder there were many files - both unsaved notes and opened existing files. They were of non-zero size in bytes but neither the ordinary Notepad, nor Notepad++ itself displayed anything. However, you can read them in Linux.

Remember to make a copy of your backup directory in case something unexpectedly goes wrong.

I recovered my unsaved notes by making a list of the file names and removing the "new" from the filename (Windows just loves spaces in file names).

for note in $(ls new*); do echo $note | grep -v new; done

This list of names can be saved in a variable and then the files can be copied to e.g .txt:

filenames=$(for note in $(ls new*); do echo $note | grep -v new; done) 
for f in $filenames ; do cp 'new '$f 'new '$f.txt; done

Suzanka

Posted 2018-07-27T15:42:11.980

Reputation: 11

1

Unless you have saved your session in the cloud, like the previous answer, you can't restore your whole session. You can, however, restore your unsaved (new) notes. They are stored at:

%APPDATA%\Notepad++\backup

You may either open all those files directly in Notepad++, or you can remake the session file in:

%APPDATA%\Notepad++\session.xml

so that the <mainView> section will include all of them.

Here's a Python script to make it easier to redo the session file. Just paste the output between the <mainView> and the </mainView> tags:

import os
import os.path as osp

npp_path = osp.join(osp.expandvars('%APPDATA%'), 'Notepad++', 'backup')
for fn in sorted(os.listdir(npp_path), key=lambda fn: fn.split('@')[1]):
    name = fn.split('@')[0]
    print('<File firstVisibleLine="0" xOffset="0" scrollWidth="64" '
          'startPos="8" endPos="8" selMode="0" lang="Normal Text" '
          'encoding="-1" userReadOnly="no" filename="{name}" '
          'backupFilePath="{npp_path}\{fn}" originalFileLastModifTimestamp="0"'
          'originalFileLastModifTimestampHigh="0" '
          'mapFirstVisibleDisplayLine="-1" mapFirstVisibleDocLine="-1" '
          'mapLastVisibleDocLine="-1" mapNbLine="-1" mapHigherPos="-1" '
          'mapWidth="-1" mapHeight="-1" mapKByteInDoc="0" '
          'mapWrapIndentMode="-1" mapIsWrap="no" />'.format(
                  name=name, npp_path=npp_path, fn=fn))

Ronan Paixão

Posted 2018-07-27T15:42:11.980

Reputation: 131