Question:
How can I get a list of all Drives and Network Locations with Python under Windows 10? The list should consist of "Local Drives", "Network Drives" and "Network Locations".
Example
TYP HD HD NETWORK LOCATION
some_list = ["C:\\", "D:\\", "\\some.network.address\some_folder"]
My Solution:
Is there a better way to solve the problem? I don't think that my shortcut parsing is a "good" solution...
import win32api
from os import getenv, listdir
from os.path import join
import win32com.client
NETWORK_SHORTCUTS_FOLDER_PATH = getenv('APPDATA') + \
"\\Microsoft\\Windows\\Network Shortcuts"
# Add Logical Drives
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
# Add Network Locations
network_shortcuts = [join(NETWORK_SHORTCUTS_FOLDER_PATH, f) +
"\\target.lnk" for f in listdir(NETWORK_SHORTCUTS_FOLDER_PATH)]
shell = win32com.client.Dispatch("WScript.Shell")
for network_shortcut in network_shortcuts:
shortcut = shell.CreateShortCut(network_shortcut)
drives.append(shortcut.Targetpath)
print(drives)