Sublime Forum

Create files from sublime plugin

#1

I can’t understand why this easy plugin don’t work (don’t create file).

class ExampleCommand(sublime_plugin.TextCommand): def run(self, edit): f = open("my.sublime-snippet", "w") f.write("Hello world") f.close()
But after any changes it works correctly.
Can anyone help me to understand this?

0 Likes

#2

Are you sure it didn’t just create the file somewhere you weren’t expecting?

0 Likes

#3

Oh, sorry, I found it in \System32, but why? I thinks that it must appeare in folder with plugin. I tried to change this plugin and resave it and after that it works. But after restarting sublime text it doesn’t work again.
P.S. And sorry for my bad english.

0 Likes

#4

Probably has to do with how/where the plugin is being executed from. Why not give the full path so you know exactly where it is being created. For example, you can use sublime.packages_path() to get the packages directory. You can then append the package name and the snippet, which are things you are defining.

0 Likes

#5

Ok. Thank you for help.

0 Likes