Forum Archive

Best practice for choosing a folder in a dialog

techteej

files1 = sorted(os.listdir(os.getcwd()), key=str.lower)
script = dialogs.list_dialog(title='', items=files1, multiple=False)
if '.py' not in script:
files1 = sorted(os.listdir(script), key=str.lower)
script = dialogs.list_dialog(title='', items=files1, multiple=False)
url = 'pythonista://' + script + '?action=run'

Pretty sure there is a better way to do this.

Gerzer

Unless I'm completely missing something obvious, there isn't an official folder dialogue. As such, your way seems to be the best you can do without recursion. Although, you could iterate over each subdirectory (presumably using os.walk) and display separate list dialogues for each subdirectory the user taps into. This would allow for the user to have as many subdirectory levels as they want. I haven't tried actually implementing such a system (I haven't had the need to) but in theory, at least, this should work.