I lost open tabs and probably, files! HELP!
-
Yes, Im have file right here. How do I can restore tabs back and edited files too?
your backup files will look like this:
unsaved tabs:new 1@2019-03-20_043157
(tab name, followed by @ and date + time)
unsaved files:yourfile.txt@2019-03-22_083021
(file name, followed by @ and a date/time stamp)- first copy them all to a new folder on your desktop.
- for unsaved files, rename your backup copy to the original file name, by removing the @ and the date/time stamp.
- for unsaved tabs, rename your backup copy to the original file name, by removing the @ and the date/time stamp, and add the extension
.txt
as they don’t have an extension yet. - open all files in notepad++ and check if you are lucky and they reflect your unsaved files and/or tabs.
-
Did you learn any kind of lesson from this experience?
-
Im always think Notepad++ always save last opened tabs as Firefox or CHrome always do
-
@Meta-Chuh said:
Yes, Im have file right here. How do I can restore tabs back and edited files too?
your backup files will look like this:
unsaved tabs:new 1@2019-03-20_043157
(tab name, followed by @ and date + time)
unsaved files:yourfile.txt@2019-03-22_083021
(file name, followed by @ and a date/time stamp)- first copy them all to a new folder on your desktop.
- for unsaved files, rename your backup copy to the original file name, by removing the @ and the date/time stamp.
- for unsaved tabs, rename your backup copy to the original file name, by removing the @ and the date/time stamp, and add the extension
.txt
as they don’t have an extension yet. - open all files in notepad++ and check if you are lucky and they reflect your unsaved files and/or tabs.
why you forgot mention session.xml in notepad++ appdata folder? I just make copy this file and replace wiped folder, and after restart porgrams N++ restore all tabs with all files and scrolls saved!
-
congratulations, if i understood everything correctly, you have been able to successfully recover your unsaved tabs and files. 👍
-
Thanks for your help, really appreciate it! :-)
-
Back to the same old way of operating!
-
@Meta-Chuh said:
make sure you don’t shutdown or reboot your pc, while notepad++ is still running.
And what if the power fails? I always reboot with NPP running and never lost any tabs until version 7.6.3. So I thought it would always recover a session, like Firefox or Microsoft Word… What a surprise when everything disappeared !
a shutdown will only halt as long as a dialogue window is open.
…but Windows Notepad halts shutdown even when a dialogue window is NOT open! – NPP should work the same way, as the user expects. (Also, NPP does not implement file locking on the contents of its own temp folder while it is running!?)
if i understood everything correctly, you have been able to successfully recover your unsaved tabs and files.
If I understood correctly, it also means that automatic session recovery should be trivial to implement in source with a “clean shutdown” flag and a backup of session.xml
@Alan-Kilborn said:
Did you learn any kind of lesson from this experience?
I think the lesson is for the developers.
Back to the same old way of operating!
Which should be supported ! 😁
-
@kekukui said:
And what if the power fails?
I think the lesson is for the developers.
You can’t be serious…If a tornado/hurricane comes to your house and smashes your computer and its hard drive into bits and your data is lost…is that something the developers should protect you from?
Save (ctrl+s, often)…and backup (independently of Notepad++, move copy offsite, also often).
-
What needs to happen to get the old functionality where tabs/files persisted across reboots?
I’ve been using the notepad++ as a persistent sticky pad for snippets of code, error messages and random state for years. The old behavior was incredibly useful. Do I need to make a fork?
-
@Douglas-Dike said:
The old behavior was incredibly useful
And the persist-across-exits-or-reboots behavior still exists. It is now, and has always been, a calculated risk on your part to enable it. If you lose data (as the OP of this thread did) because Windows crashed, don’t blame Notepad++; anyone relying on an auto-save to not be corrupted during OS crash is taking the consequences of their own decision: it’s not a danger specific to Notepad++: I’ve lost data because MS Word auto-save feature corrupted both the original file and the periodic auto-backup. I always recommend taking full control of critical data (“save early, save often; commit early, commit often” is my mantra).
And that behavior is now, and has always been (*) enabled via the Settings > Preferences > Backup > Enable Session Snapshot and periodic backup.
(*: “always” may be an overstatement. I doubt the feature existed in Notepad++ before Notepad++ existed; I don’t know what version number Notepad++ added the session-snapshot/periodic-backup feature. But as long as I’ve known about that feature, it’s been at that setting.)
-
welcome to the notepad++ community, @Douglas-Dike
What needs to happen to get the old functionality where tabs/files persisted across reboots?
this code part has not changed.
what has changed, is that you are probably on windows 10, or worse: on w10 build 1809, which will currently force kill applications on automatic windows update reboots, with a more limited grace period, for a “better microsoft user experience” due to faster rebooting.Do I need to make a fork?
no, you just have to install any of the older versions, which you think worked before, from here:
https://notepad-plus-plus.org/download/all-versions.html
to personally verify that notepad++ has not changed regarding “tabs/files persisting across reboots”, but your windows platform it is running on.eventually you could also dig out your good old win7 dvd and “repair” win10 with it ;-)
-
Please update the code for saving current session from time to time to fix the issue with lost sessions on reboot. This is seriously impacting work with NPP as lost sessions/files is very bad experience.
Thank you. -
the bug seems to have been fixed, thank you.
otherwise, please comment in the bug report:
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/10402#
-
I have encountered this problem a couple of days ago, my laptop had a BSOD and seems that the session.xml was corrupted or lost.
If the “%AppData%\Notepad++\backup” still has the files, you can create a backup in your desktop and use the following c# program to re-create the “session.xml” file.
Completely close Notepad++ and execute the following c# script:// Restores session.xml file in %AppData\Roaming\Notepad++ // from files stored in %AppData\Roaming\Notepad++\backup using System; using System.IO; string app_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string path = app_path + @"\Notepad++\backup\"; string fullfile = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<NotepadPlus> \n<Session activeView=\"0\"> \n<mainView activeIndex=\"2\">"; string endtext = "</mainView>\n <subView activeIndex=\"0\" />\n</Session>\n</NotepadPlus>"; string entry1 = "<File firstVisibleLine=\"0\" xOffset=\"0\" scrollWidth=\"64\" startPos=\"8\" endPos=\"8\" selMode=\"0\" offset=\"0\" wrapCount=\"1\" lang=\"None (Normal Text)\" encoding=\"-1\" userReadOnly=\"no\" filename=\""; string entry2 = "backupFilePath=\""; string endentry = "originalFileLastModifTimestamp=\"0\" originalFileLastModifTimestampHigh=\"0\" mapFirstVisibleDisplayLine=\"-1\" mapFirstVisibleDocLine=\"-1\" mapLastVisibleDocLine=\"-1\" mapNbLine=\"-1\" mapHigherPos=\"-1\" mapWidth=\"-1\" mapHeight=\"-1\" mapKByteInDoc=\"512\" mapWrapIndentMode=\"-1\" mapIsWrap=\"no\" />"; string[] filenames = Directory.GetFiles(path); foreach (string filename in filenames) { int istart = filename.IndexOf("kup\\")+4; int iend = filename.IndexOf("@"); string entryname = filename.Substring(istart,iend-istart); string fullname = filename.Substring(istart); fullfile = fullfile + entry1 + entryname + "\" " + entry2 + filename + "\" " + endentry + "\n"; } fullfile = fullfile + endtext; Console.WriteLine (fullfile); // If you want to test the output, comment the line below or change the path. File.WriteAllText(app_path + @"\session.xml",fullfile);
This could be done with Powershell too, may look into it so that it is a bit more accessible.
-
@sfcfs The last line of the code needs to be changed to
File.WriteAllText(app_path + @"\NotePad++\session.xml",fullfile);
for it to work seamlessly. If not the user needs to move the session.xml file from the folder %AppData%\Roaming to %AppData%\Roaming\Notepad++
After that, just start Notepad++ and your tabs should be back.
-
Just a clarification:
@sfcfs said two posts ago:
%AppData%\Notepad++\backup
and then one post ago:
%AppData%\Roaming to %AppData%\Roaming\Notepad++
The first (
%AppData%\Notepad++\*
) was correct. The second (%AppData%\Roaming\*
) is wrong. See the AppData FAQ. Try it yourself: open Windows Explorer, and paste/type%AppData%\Roaming
into the title/address bar and see the error message that pops up; then try%AppData%\Notepad++
and see what happens.Other than that mistake (which many people make), that’s a great script, so thanks for sharing.
Also, it would be nice, for those who aren’t C# experts, if you showed how an average-Joe Notepad++ user, who might not have ever touched C#, could take that C# code and actually compile/run it (without having to install a huge C# environment) – not all Notepad++ are C# programmers, or programmers at all.
----
Addenda: See, for example, this post, where I show errors I get when I tried to compile your script with the .NET framework’s csc.exe using
c:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe recover-lost-session.cs
:recover-lost-session.cs(6,1): error CS0116: A namespace cannot directly contain members such as fields or methods recover-lost-session.cs(13,8): error CS1001: Identifier expected recover-lost-session.cs(13,10): error CS1518: Expected class, delegate, enum, interface, or struct
-
Here is a PythonScript implementation of it.
See these instructions for how to run this script in PythonScript
The script will pop up a dialog. Respond with:
- click YES to load the recovered session immediately
- click NO to save the recovered session into an XML file that you can later load with File > Load Session…
- click CANCEL to ignore the recovered session
This is only effective if Settings > Preferences > Backup > Enable session snapshot… was checkmarked before you lost your session file. This is only effective if nothing happened to erase
%AppData%\Notepad++\backup
or equiavlent.Script:
RecoverLostSession.py
# encoding=utf-8 """in response to https://community.notepad-plus-plus.org/topic/17344/ specifically, translate the ideas behind https://community.notepad-plus-plus.org/post/79695 to PythonScript 0. Install Python Script plugin, if not yet installed 1. Use Plugins > PythonScript > New Script, give this a name (like `RecoverLostSession.py`) 2. Plugins > PythonScript > Scripts > `RecoverLostSession` to recover it 1. click YES to load the recovered session immediately 2. click NO to save the recovered session into an XML file that you can later load with File > Load Session... 3. click CANCEL to ignore the recovered session """ from Npp import editor,notepad,console import os import tempfile class SessionRecovery(object): xml_prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<NotepadPlus> \n<Session activeView=\"0\"> \n<mainView activeIndex=\"2\">" xml_suffix = "</mainView>\n <subView activeIndex=\"0\" />\n</Session>\n</NotepadPlus>\n" xml_entry1 = "<File firstVisibleLine=\"0\" xOffset=\"0\" scrollWidth=\"64\" startPos=\"8\" endPos=\"8\" selMode=\"0\" offset=\"0\" wrapCount=\"1\" lang=\"None (Normal Text)\" encoding=\"-1\" userReadOnly=\"no\" filename=\"" xml_entry2 = "backupFilePath=\"" xml_endentry = "originalFileLastModifTimestamp=\"0\" originalFileLastModifTimestampHigh=\"0\" mapFirstVisibleDisplayLine=\"-1\" mapFirstVisibleDocLine=\"-1\" mapLastVisibleDocLine=\"-1\" mapNbLine=\"-1\" mapHigherPos=\"-1\" mapWidth=\"-1\" mapHeight=\"-1\" mapKByteInDoc=\"512\" mapWrapIndentMode=\"-1\" mapIsWrap=\"no\" />" xml_full = "" def go(self): self.determine_directories() self.build_xml() s = notepad.messageBox("YES to load recovered session now\nNO to save as a new session file\nCANCEL to ignore recovered session", "Recovered Session", MESSAGEBOXFLAGS.YESNOCANCEL) if s == MESSAGEBOXFLAGS.RESULTYES: self.load_session() elif s == MESSAGEBOXFLAGS.RESULTNO: self.saveas_session() return def determine_directories(self): cfg_plg_cfg = notepad.getPluginConfigDir() (cfg_plg, x) = os.path.split(cfg_plg_cfg) (self.cfg_dir, x) = os.path.split(cfg_plg) self.bkup_dir = os.path.join(self.cfg_dir, 'backup') self.xml_full = self.xml_prefix self.session_xml_path = os.path.join(self.cfg_dir, 'session.xml') return def build_xml(self): for (root, dirs, files) in os.walk(self.bkup_dir): for f in files: filepath = os.path.join(root, f) posFile = filepath.find(f) posAt = filepath.find("@") entry_name = filepath[posFile:posAt] this_entry = self.xml_entry1 + entry_name + '" ' + self.xml_entry2 + filepath + '" ' + self.xml_endentry + "\n" self.xml_full += "\n " + this_entry self.xml_full += self.xml_suffix return def saveas_session(self): notepad.new() editor.setText(self.xml_full) notepad.save() notepad.close() return def load_session(self): _, fn = tempfile.mkstemp('.xml') f = open(fn, 'w') f.write(self.xml_full) f.close() notepad.loadSession(f.name) try: os.remove(f.name) except WindowsError as e: if e.winerror == 32: # cannot delete is fine, just ignore it pass else: raise e return SessionRecovery().go()
-
P PeterJones referenced this topic on
-
HERE’s another variation on Python code “solving” the problem.
-
I am also facing the same issue, I am using Notepad ++ 5. +.+