Is there a way to set %USERNAME% in the path?
I saved a workspace in two computers with different user names like this:
<File name="C:\Users\MyUsername\project\filename.docx" />
My question is, is there a way to let Notepad++ know the username automatically?
For example, like in batch command, if you echo %USERNAME%, then " %USERNAME%" will be replaced by your actual user name.
There a different ways to do this. The question is what do you exactly expect?
Should npp replace a variable if you open a file or if you save it or close it …
Maybe you can give us a short example what you want to achive.
@瀚程戴 is talking about the session file from File > Save Session…
It looks like Notepad++ does not resolve the path containing an environment variable.
afaik npp doesn’t expand environment variables in this case.
What could be done so is to use a python script like
import os for _file in notepad.getSessionFiles('PATH_SESSION_FILENAME'): notepad.open(os.path.expandvars(_file))
where PATH_SESSION_FILENAME needs to be replace with your session file, of course.
If this python script should be executed right after npp started you need to copy the lines
to startup.py file and change initialisation to ATSTARTUP in python script configuration window.
You guys got my point although I didn’t make it clear enough. It’s a pity that npp could not get an environmental variable.
Just let you know my demand better and my solution in R:
user <- System$getUsername()
directory <- paste(“C:\\Users\\”, user, “\\workspace”, sep="")
With the above code, I could set the working directory correctly regardless of which computer I use, so it’s easy for me to switch different computers.