it’s not exactly what you want but here are a couple of commands that list the current directory tree using depth first and breadth first search.
import sublime, sublimeplugin
import os.path
import functools
badExtensions = '.jpg', '.gif', '.png', '.pyc', '.pyo', '.bin', '.o',
'.so', '.obj', '.lib', '.pdb', '.suo', '.ncb', '.dll', '.exe', '.zip',
'.tar', '.gz', '.bz2', '.tgz', '.rar', '.pdf', '.doc', '.tmp', '.bak']
def wantFile(cwd, f):
root, ext = os.path.splitext(f)
return os.path.isfile(os.path.join(cwd,f)) and not ext in badExtensions
class PromptOpenFileInCurrentDirectoryTreeDFSCommand(sublimeplugin.WindowCommand):
"""Open a file in the current directory tree using dfs"""
def run(self, window, args):
cwd = os.getcwdu()
files = ]
cnt = 0
max = 1000
for root, subFolders, filesInFolder in os.walk(cwd):
for file in filesInFolder:
if wantFile(root,file):
files.append(os.path.join(root,file))
cnt += 1
if cnt>=max: break
if cnt>=max: break
if cnt>=max: break
# construct list of files minus the top directory for display
l = 1+len(cwd)
displayFiles = [f[l:] for f in files]
window.showQuickPanel("", "open", files, displayFiles,
sublime.QUICK_PANEL_FILES | sublime.QUICK_PANEL_MULTI_SELECT)
class PromptOpenFileInCurrentDirectoryTreeCommand(sublimeplugin.WindowCommand):
"""Open a file in the current directory tree using breadth first search"""
# code taken from http://code.activestate.com/recipes/511456/
def breadthFirstFileScan( self, root, max ) :
cnt = 0
dirs = [root]
# while we have dirs to scan
while len(dirs) :
nextDirs = ]
for parent in dirs :
# scan each dir
for f in os.listdir( parent ) :
# if there is a dir, then save for next ittr
# if it is a file then yield it (we'll return later)
ff = os.path.join( parent, f )
if os.path.isdir( ff ) :
nextDirs.append( ff )
else :
if wantFile(parent, f):
yield ff
cnt += 1
if cnt >= max: return
# once we've done all the current dirs then
# we set up the next itter as the child dirs
# from the current itter.
dirs = nextDirs
def run(self, window, args):
cwd = os.getcwdu()
files = ]
for f in self.breadthFirstFileScan( cwd, 1000 ) :
files.append( f)
# construct list of files minus the top directory for display
l = 1+len(cwd)
displayFiles = [f[l:] for f in files]
window.showQuickPanel("", "open", files, displayFiles,
sublime.QUICK_PANEL_FILES | sublime.QUICK_PANEL_MULTI_SELECT)