Sublime Forum

Is there a plugin that lets me open all the files listed in a text file?

#1

So I could have a text list like this:

c:\users\me\desktop\a_text_file.txt
d:\a_directory\some_other_file.log
c:\temp\a_third_one.xml

Then I can execute a single command to make the plugin read that list and open all the files.

Anything like that exist?

0 Likes

#2

Should exists, but if it is published on the internet, I do not know. You could write so with python.

For each line, open the file path

See:

  1. https://www.sublimetext.com/docs/3/api_reference.html
  2. http://www.sublimetext.com/docs/plugin-basics
  3. http://docs.sublimetext.info/en/latest/extensibility/plugins.html
0 Likes

#3

Thanks, I think I will end up writing my own. Should be easy enough!

1 Like

#4

Wrote my own. This works just fine for my purposes.

import sublime
import sublime_plugin
import os.path

class OpenFilesInListCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        # Open in this window
        this_window = self.view.window()
        
        # Grab contents of current view
        view_contents = self.view.substr(sublime.Region(0, self.view.size()))

        # Split on newline
        view_contents = view_contents.splitlines()

        # Go through each line, open each file
        for file in view_contents:
            if (file == ''):
                continue
            
            this_window.open_file(os.path.abspath(file))
5 Likes