[英]python-get physical disk info from logical path
I have the logical paths. 我有逻辑路径。 For instance:- path1='C:/abc', path2='E:/xyz'
例如:-path1 ='C:/ abc',path2 ='E:/ xyz'
I want to check if both of them reside on same physical disk. 我想检查它们是否都位于同一物理磁盘上。
Or in general I want to map a logical path to associated physical drives. 或者通常,我想将逻辑路径映射到关联的物理驱动器。
I would also want to do the same for linux. 我也想对linux做同样的事情。 For now I use "os.stat(path).st_dev" to get the device id.
现在,我使用“ os.stat(path).st_dev”来获取设备ID。 But the id seems to be different for logical disks on same same physical drive.
但是,同一物理驱动器上的逻辑磁盘的id似乎不同。 So it doesn't actully work for me.
因此,它对我不起作用。 Is there a better or direct solution to it.
是否有更好或更直接的解决方案。
This solved my problem 这解决了我的问题
key = ''
for physical_disk in w.Win32_DiskDrive():
logical_disks = []
for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
key = logical_disk.Description
if key not in all_logical_disks:
all_logical_disks[key] = []
logical_disks.append(logical_disk.Caption)
if logical_disks:
all_logical_disks[key].append(logical_disks)
This helped me to get a dict of type: {u'Local Fixed Disk': [[u'C:', u'D:'],[u'E:', u'F:']]} which grouped logical patitions in different physical disks. 这帮助我得到了以下类型的字典:{u'Local Fixed Disk':[[u'C:',u'D:'],[u'E:',u'F:']]}}不同物理磁盘中的逻辑分区。 Now I can compare if the logical paths lie in the same list.
现在,我可以比较逻辑路径是否在同一列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.