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=''):
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):
return output
@ -1217,16 +1229,15 @@ def browse_path(path=None, include_hidden=False, filter_ext=''):
}
output.append(out)
elif os.name == 'nt':
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': 'level-up-alt'
}
output.append(out)
parent_path = 'My Computer'
out = {
'key': base64.b64encode(parent_path.encode('UTF-8')),
'path': parent_path,
'title': parent_path,
'type': 'folder',
'icon': 'level-up-alt'
}
output.append(out)
for root, dirs, files in os.walk(path):
for d in sorted(dirs):