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?
