To open multiple files by means of NppExec, use npp_open:
npp_open file_path_1 npp_open file_path_2 npp_open file_path_3
The example above opens 3 files in Notepad++ and the last opened file becomes active.
If you want to preserve the order of opening these files but activate the first one (instead of the last one), use npp_switch at the end:
npp_open file_path_1 npp_open file_path_2 npp_open file_path_3 npp_switch file_path_1
Both npp_open and npp_switch accept full file paths and relative file paths.
Moreover, npp_switch also supports partial file names. For example, npp_switch abc will switch to the first opened file that contains "abc" in its name.
It is possible to open multiple files by specifying a file mask. For example, this will open all .txt files from a given directory:
npp_open C:\some_dir\*.txt
In this case, if you want to switch to the very first file opened by npp_open, a few additional commands are needed.
At first, we need to remember the number of opened files before npp_open. Let's say this number is N.
Then we call npp_open to open multiple files.
Finally, we switch to the (N+1)th opened file.
Here is the corresponding NppExec's script:
// 1. remembering the number of opened files npp_sendmsg NPPM_GETCURRENTSCINTILLA 0 @0 set local view ~ $(MSG_LPARAM) + 1 npp_sendmsg NPPM_GETNBOPENFILES 0 $(view) set local num_opened_files = $(MSG_RESULT) // 2. calling npp_open npp_open C:\some_dir\*.txt // 3. switching to the (num_opened_files + 1)th document set local file_idx ~ $(num_opened_files) + 1 npp_switch $(#$(file_idx))
Just for information, npp_switch $(#$(file_idx)) becomes e.g. npp_switch $(#5) when the value of $(file_idx) is 5.
This trick is called "indirect variable reference, e.g. $($(name))" and was added in NppExec v0.6.2.