Is it possible to dump the names of all the open files in notepad++ to a file

notepad

So, I dragged and dropped multiple files onto notepad++. The files came from different directories and were selected using different criteria.

So, I have many files open in Notepad++. Now I need to have a list of all the open files in another file.

Right now, my only option is to script the decisions used to guide me in selecting the files in the first place. Which is probably the best in the long term, but I wonder if there is a quicky one in Notepad++. Some plugin magic or whatever.

Suggesting another free editor which has this function is a good option too (not that I am going to ditch notepad++, God forbid)

Best Answer

Yes, Install Python Script Plugin Plugin Manager.

After installing Python console, toggle the Python console.

Type this in the console:

notepad.getFiles()

to return all open files as a List type:

[('C:\\Users\\ahmed\\Desktop\\1999.txt', 32818504, 0, 0), ('D:\\WORKSPACE\\imza\\e-mail.html', 32721752, 1, 0), ('new  1', 32721944, 0, 1)]

The code below is one-shot command to retrieve the file names, and is suitable for Python Script command line. You can extend it with persistent Python scripts.

fileNames = [n[0] for n in notepad.getFiles()]

How to dump this fileNames to an existing file or newly created file

Current File: Paste this code and hit Enter twice.

for f in fileNames: editor.appendText(f + '\n')

New File Paste this code.

notepad.new() ; for f in fileNames: editor.appendText(f + '\n')

It is also possible dump to an external file, this snippet from http://npppythonscript.sourceforge.net/ is easy to understand even if you are not familiar with Python:

externalFile='_log.log'; console.run('cmd /c ls > "%s"' % externalFile, editor) 

Documentation

Comprehensive documenation is avaible in http://npppythonscript.sourceforge.net/docs/latest/ with Python Primer tutorial.

Related Question