Natomiast raczej nie odróżnisz łatwo pendrive'a od dysku
niekoniecznie, spróbuj użyć psutil [ 1 ] [ 2 ] [ 3 ]
psutil.disk_partitions() – This function provides the details of all mounted disk partitions as a list of tuples including device, mount point and filesystem type.
import psutil
print(psutil.disk_partitions())
input()
W windows-ie wyświetla powyższe polecenie takie np. dane
[
sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260),
sdiskpart(device='D:\\', mountpoint='D:\\', fstype='FAT32', opts='rw,removable', maxfile=255, maxpath=260),
sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260)
]
import psutil
drives = []
for partition in psutil.disk_partitions():
drives.append([partition.device, partition.opts])
print(drives)
input()
[
['C:\\', 'rw,fixed'],
['D:\\', 'rw,removable'],
['E:\\', 'rw,fixed']
]
chyba łatwo się domyślić, który dysk jest "stały", a który to pendrive i czy umożliwia zapis, czy odczyt.
przykład
import psutil
def get_fixed_drive_list():
excluded_drive_types = ['removable', 'network', 'cdrom', 'ramdisk']
drives = []
for partition in psutil.disk_partitions():
if not partition.opts.split(',')[1] in excluded_drive_types:
drives.append([partition.device, partition.opts])
return drives
if __name__ == "__main__":
print(get_fixed_drive_list())
input()