Sublime Forum

Sublime API and `subst` on Windows

#1

I’ve noticed some ‘strange’ behaviour recently when I tried to write a simple plugin to recursively search up directories until a specific file was found (Recursivley search up directories until file is found in build system).

In that thread I posted my solution to the problem, but in the Python code I wrote I had to do the following:

dir = self.view.window().active_view().file_name()
dir = dir.replace(':', ':\\').replace('\\\\', '\\')

This is because the string returned by file_name() was missing the backslash after the drive which caused some problems with the os.path.isfile() call I was making.

The only thing I can find that is different about the file I was testing in is that the path file_name() returns is actually using a drive that I created with subst in the Windows command line.

When it returns a path using an actual drive letter this problem doesn’t happen.

For example, if I do the following in Windows cmd:

subst G: C:\projects

And I use the self.view.window().active_view().file_name() function from a file within that directory, lets say C:\projects\some-folder it seems to return G:some-folder instead of G:\some-folder.

If however I don’t use subst it correctly returns C:\projects\some-folder without missing the backslash after the colon.

I fully admit that I have very little experience with Python and Sublime Text Plugin creation, so I’m not sure what the problem is.

Is this a problem with the Windows subst command, Python itself, or does the problem lie with the Sublime Text API?

0 Likes

#2

Never mind, once again immediately after posting my question I found my own answer :sweat_smile:

I had a bat file in my startup folder that was doing: subst g: c:\projects instead of subst G: C:\projects.

I guess the case of the drive letter makes a difference somehow.

0 Likes