Improve browsing for path on Windows

This commit is contained in:
JonnyWong16 2020-05-08 17:54:14 -07:00
parent bc017fb010
commit 6c8b425fb3
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -1203,6 +1203,18 @@ def user_page(user_id=None, user=None):
def browse_path(path=None, include_hidden=False, filter_ext=''): def browse_path(path=None, include_hidden=False, filter_ext=''):
output = [] output = []
if os.name == 'nt' and path.lower() == 'my computer':
drives = ['%s:\\' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
for drive in drives:
out = {
'key': base64.b64encode(drive.encode('UTF-8')),
'path': drive,
'title': drive,
'type': 'folder',
'icon': 'folder'
}
output.append(out)
if not os.path.isdir(path): if not os.path.isdir(path):
return output return output
@ -1217,16 +1229,15 @@ def browse_path(path=None, include_hidden=False, filter_ext=''):
} }
output.append(out) output.append(out)
elif os.name == 'nt': elif os.name == 'nt':
drives = ['%s:\\' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)] parent_path = 'My Computer'
for drive in drives: out = {
out = { 'key': base64.b64encode(parent_path.encode('UTF-8')),
'key': base64.b64encode(drive.encode('UTF-8')), 'path': parent_path,
'path': drive, 'title': parent_path,
'title': drive, 'type': 'folder',
'type': 'folder', 'icon': 'level-up-alt'
'icon': 'level-up-alt' }
} output.append(out)
output.append(out)
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for d in sorted(dirs): for d in sorted(dirs):