Sublime Forum

Window open_file

#1

Hello,

Apologies in advance for such a newbie question. I have searched the Forum and have tried numerous approaches, but I can’t seem to get the Window open_file function to open a file! I have a TextCommand plugin with the following code that does not work, I get the error from Sublime: “Unable to open /home/public_html/asciidoc/functions/sys_init.txt”. Help greatly appreciated! I am on a Windows computer. Note: the call to os.path.exists is successful.

    filepath = '/home/public_html/asciidoc/functions/'
    filename = 'sys_init.txt'
    if os.path.exists(filepath+filename):
        v = sublime.active_window().open_file(filepath+filename)
    else:
        print('Oops!')
    return 0
0 Likes

#2

It should work if you prepend the drive letter to the path

0 Likes

#3

because ‘os.path.exists’ defaults to a different root than Sublime’s ‘open_file’ - which defaults to the current project folder, or Packages path, I believe.

In case it’s an issue, print() is Python 3.0 and ST defaults to its own local copy of Python 2.6 or 2.7.

0 Likes

#4

Thank you! Adding “C:” to the path worked! It would have taken me some time to try that. That is interesting stuff indeed! I’m not accustomed to including a drive letter in the path, my experience has been that the default drive is assumed. Live and learn!

0 Likes