PythonScript
PythonScript copied to clipboard
[Feat. Req.] Consider adding notepad.getNppConfigDir()
Recently I had a need to open (for reading) the default session file (session.xml) from a PythonScript.
Locating the file was tedious as I first had to figure out where it was.
PS currently has notepad.getNppDir() and notepad.getPluginConfigDir() functions, and it would be nice to see the addition of notepad.getNppConfigDir().
Comments based on functionality from PS 2.0 and 3.10.4.
Here's my workaround script code:
# -*- coding: utf-8 -*-
from __future__ import print_function
from Npp import *
def notepad_getNppConfigDir():
npp_dir = notepad.getNppDir()
plugin_cfg_dir = notepad.getPluginConfigDir()
if plugin_cfg_dir.startswith(npp_dir):
npp_config_dir = npp_dir # portable version of N++
else:
# installed (%APPDATA%) version of N++
npp_config_dir = os.path.join(plugin_cfg_dir, '..', '..')
npp_config_dir = os.path.abspath(npp_config_dir)
return npp_config_dir
npp_cfg_dir = notepad_getNppConfigDir()
print('npp_cfg_dir:', npp_cfg_dir)
Note: Sample code doesn't consider settings stored in the "cloud", but it, and the suggested new function, should.