Skip to content

Instantly share code, notes, and snippets.

@WindfallLabs
Created July 7, 2016 15:21
Show Gist options
  • Save WindfallLabs/334c96fd7128f6ca586615f31fd1631c to your computer and use it in GitHub Desktop.
Save WindfallLabs/334c96fd7128f6ca586615f31fd1631c to your computer and use it in GitHub Desktop.
get_users.py -- Searches Window's /Users/ file for write-accessable user folders
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
get_users.py -- Searches Window's /Users/ file for write-accessable user folders
and returns a list of write-accessible folder names (i.e. likely user name).
"""
import os
def get_users():
users_dir = r"C:\Users"
ignore = {"All Users", "Default", "Public"}
users = set()
for path in os.listdir(users_dir):
try:
os.listdir(os.path.join(users_dir, path))
users.add(path)
except WindowsError:
pass
return list(users.difference(ignore))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment