# Issue with "session.xml" in N++ v7.9 (portable)?

• Hi All,

I use the portable version v7.9 of N++, so that I can work without problems on different computers, even the ones which do not have N++ installed.
However, I note that the session I end on one machine, does not load again when I start a new session on another machine. Which I can tell by my chosen language (Python) which is no longer set, and also a couple of bookmarks which are gone.

These bookmarks are present alright, when I shut down N++ next start it again on the same machine. But not on another computer.
Yet, “session.xml” is present in the “Tool” sub-dir (I assume its default location), and its version is correct: not only the file’s “date modified” tells me so, but also the bookmarks mentioned, whose presence in the “session.xml” file I can easily verify.
So, is there a way I can force “session.xml” to be loaded when launching N++? To make sure that I will start up my last session again, regardless of the machine I’m working on?

Incidently, my settings are identical to the screenshot in this post:
Also, I verified that the correct (portable) N++ version is running, and not some other N++ version which happens to be installed on the computer I’m using.

Which can be verified in the Debug info: (H: being a USB key)

Build time : Sep 22 2020 - 03:19:04
Local Conf mode : ON
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 1909
OS Build : 18363.1256
Current ANSI codepage : 1252
Plugins : LuaScript.dll mimeTools.dll NppConverter.dll NppExport.dll XMLTools.dll

GH-2017

• @Michel-Kempeneers ,

When in portable/local config mode, if Settings > Preferences > Backup > Remember current session for next launch is enabled, it should automatically load the session.xml that is present in the same folder as notepad++.exe, which is what your description implies.

I just unzipped a fresh 7.9 64-bit, and confirmed it worked as I explained.

The session saves the full path to the file, so hopefully the file you are editing is in the same exact path on every machine: note, even if the file is on the USB drive, the path must be the same – if one machine puts the USB as H: but the other puts it as J:, the files cannot be loaded.

• @PeterJones

So the path is actually the issue, thx for pointing that out!
Which cannot easily be solved, because a USB key tends to get another drive letter attributed depending on the configuration of the computer it is plugged into. And which will be different if other carriers were already plugged in.

Is there a possibility to use a batch file (command line) which would load “session.xml”? As there is a “Load session…” feature in the File menu, I guess it must be possible to work around the drive letter issue that way?

GH-2017

• Is there a possibility to use a batch file (command line) which would load “session.xml”?

That was the direction I was heading. I can only suggest using a batch file to first find the current working directory of the batch file which exists on the USB stick. Read here for some info on that:

Then use the SUBST command to map the “correct” drive to a sub folder within the USB stick which houses the Notepad++ portable installation.
It will mean some extra work involved in re-setting up the portable installation so it might have to reside another level down in folders. Also rejigging the drive it appears to run from (a one time setup). Also consider using a later character in the alphabet so that chances of it already being taken are minimised. Even consider having the batch file check for existence of that drive letter first so you can avoid creating further issues if trying to re-map it.

Good luck. It is a nice idea to run from USB stick but as you found out Windows has other ideas on how the environment is setup.

Terry

• Is there a possibility to use a batch file (command line) which would load “session.xml”?

notepad++.exe -openSession path\to\file.xml

(see command line options documentation)

As there is a “Load session…” feature in the File menu, I guess it must be possible to work around the drive letter issue that way?

Nope. The problem isn’t that the session file was on H: on one computer and on J: on the other computer. The problem is that inside the session file, the path to the active files is stored as H:...blah\file1.txt, so that session file will not be able to open J:...blah\file1.txt.

Unless what you meant is that you wanted a bunch of session files available, like h-session.xml and j-session.xml, where h-session stores all the path names with H: and j-session stores the same path names, but with J:. That would be doable with the -openSession – assuming that you aren’t changing what files are opened. Trying to maintain that setup if you wanted to be able to change what files are in the session would be a nightmare.

• @PeterJones
I agree: I like this wild idea of using a session file per drive, but in practice that would be sheer madness.
I hadn’t checked the CL possibilities yet, as I haven’t been there before, so thx for pointing me to that specific possibility. If the path can be relative instead of absolute (which is currently my problem), that’s definitely the way to go.

@Terry-R
re-mapping may turn out to be quite complexe.
I think it’s easier to establish the actual drive letter, next use that to locate the session file. Unless this can be avoided by using a relative path in the command suggested by Peter. Sth. for the w/e. :-)
And yes, running a portable N++ from a USB stick turns out to be very practical, also because the whole set-up is altogether pretty light. Even my current issue isn’t really blocking, I’m merely trying to optimize my use of this great tool.

GH-2017

• If the path can be relative instead of absolute (which is currently my problem), that’s definitely the way to go.

I wonder, since the installation is “portable” that the concept of relative locations might be something to put forward as a feature request. It seems logical that the portable location might be something to “pick up” and then “store” on another PC, and USB use is merely an extension of that capability.

Terry

• Maybe instead of trying to do a batch file to modify/trick the drive name, and try to load a session… maybe you could use the batch file to just call notepad++ and open the individual files, relative to the notepad++ location: example =

.\notepad++.exe    "change.log"   "..\..\other\folder\file2.txt" "..\..\third\folder\file3.txt"


That way, everything could be relative.

the concept of relative locations might be something to put forward as a feature request

I actually thought there had been at least one relative-session feature request… yep: issue #5098. So @GH-2017 , you might want to cast your vote on that feature request.

• @PeterJones
This issue/feature-request is indeed the same situation I started this topic for. Not much activity there, though… How does one cast a vote?

As for your batch suggestion: I need “session.xml” to carry along my bookmarks.
AFAIU, “session.xml” is the only way this can be achieved?
And from what I see in the documentation you point me to, I cannot open both a session and some N++ file as arguments. (probably because the session file already contains a source file) Or can I?

In the mean time I did a quick test, and the following seems to work alright when I correct the stored drive letter to “F”:

F:\Notepad++ 7.9 [x64 - PORTABLE]\Tool>notepad++ -openSession _session.xml


I.e. bookmarks appear correctly, confirming what’s been mentioned before.

GH-2017

• @Terry-R
Thx for the link to that page with different solutions for fetching a drive letter.
I finally preferred to do it my own way, also because I’d rather stay away from additional tools, even freeware, or complex regex for such simple tasks.

I think I found an elegant solution, though it assumes that only one path (for the “previous” N++ file) can be present. Maybe one of the N++ gurus here can conform if that is a correct? (assuming the session is limited to a single file as I don’t need multi-files; otherwise some extra testing should be added to the code.)

I’m not sure if the idea is to share the essence of the batch here; if not, no doubt a moderator will remove it. :-)
I’ve tested it on several computers (both Win7 and Win10), all attributing another drive letter to my USB key, and it works alright!
It is a bit slow though, due to the size of my “session.xml”. (appr. 25 Kb, for some 600 lines)

@echo off

:: 1. SETTINGS ::
setlocal EnableDelayedExpansion

set "output=New.txt"
set "DL=Driveletter.txt"
set "sess_name=session"
set "sess_ext=xml"
set "DrLetter="
set "sep=:"
set "del_err= >NUL 2>NUL"

:: 2. LOGIC ::
DIR *.bat > %DL%
FOR /F "skip=3 tokens=1-3* delims=: " %%j IN (%DL%) DO (
IF "%%j" EQU "Directory" (set DrLetter=%%l)
)
DEL %DL% /Q %del_err%

echo letter = %DrLetter%
echo.

FOR /F "tokens=1-2 delims=%sep%" %%a in (%sess_name%.%sess_ext%) do (
IF "%%b" NEQ "" (
set str=%%a
echo !str:~1,-1!%DrLetter%:%%b>>%output%
) ELSE (
echo %%a>>%output%
)
)



One final remark:
it seems that the new output file can have any name, and doesn’t even require the xml extension.
N++ is smart enough to recognize its internal structure, i.e. corresponding to a session file.
So any session file can be processed, next be loaded by the batch. It suffices to adapt name and extension in the settings.

GH-2017
(Win7/Win10 - portable Notepad++ v7.9, 64-bit)

• Hello, @gh-2017, @peterjones, @terry-r and All,

I tried your batch file with few simplifications and it worked nice ! Thanks for sharing !

Now, here is a more simple version of what you expect to, which uses a tiny executable file, named mtrw.exe ( Instructions in comments )

@echo off

REM -------------------------- IMPORTANT -----------------------------------

REM  BEFORE executing this BATCH file :

REM    - EXTRACT the "mtrw.exe" file in the LOCATION of this BATCH file

REM ------------------------------------------------------------------------

REM  Copy the "session.xml" file as "New.txt", WITHOUT any CONFIRMATION message

copy /y session.xml New.txt > NUL

REM -----------------------------------------------------------------------------------------------------------------------
REM  Replace, in the "New.txt" file, the DRIVE letter and the COLON of each ABSOLUTE PATH in ALL "file..." tags with
REM    the CURRENT DRIVE letter and the COLON ( So, the TWO FIRST characters of the INTERNAL ENVIRONMENT variable %CD% )
REM
REM    (-x)  Search REGEX mode by DEFAULT
REM    -qn   QUIET mode and NO prompting
REM    -c-   SENSIBLE to CASE
REM    -b-   NO BACKUP file
REM
REM  Type "mtrw"          and ENTER for a QUICK summary
REM  Type "mtrw -?"       and ENTER to open the HELP file
REM  Type "mtrw -?:Option and ENTER for HELP on a specific OPTION
REM -----------------------------------------------------------------------------------------------------------------------

mtrw.exe -qn -c- -b- New.txt [A-Z]: = %CD:~0,2%

REM  STARTS Notepad++ and opens ALL the files contained in "New.txt", ONLY !