-
Notifications
You must be signed in to change notification settings - Fork 26
/
drive_detect.py
32 lines (25 loc) · 1.02 KB
/
drive_detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import platform
import os
if(platform.system() is 'Windows'):
import win32api
import win32con
#Function to get all removable mountpoints attached to the computer
def get_mounts():
mountpoints = []
if(platform.system() == 'Linux'):
f = open('/proc/mounts')
dev_types = ['/dev/sda', '/dev/sdc', '/dev/sdb', '/dev/hda', '/dev/hdc', '/dev/hdb', '/dev/nvme']
for line in f:
details = line.split()
if(details[0][:-1] in dev_types):
if(details[1] != '/boot/efi'):
details_decoded_string = bytes(details[1], "utf-8").decode("unicode_escape")
mountpoints.append(details_decoded_string)
f.close()
elif(platform.system() == 'Darwin'):
for mountpoint in os.listdir('/Volumes/'):
mountpoints.append('/Volumes/' + mountpoint)
elif(platform.system() == 'Windows'):
mountpoints = win32api.GetLogicalDriveStrings()
mountpoints = mountpoints.split('\000')[:-1]
return mountpoints