Determine which physical hard drive the file is on?

How to find the physical disk where the file / directory is located. I want to compare 2 files, and if they are on two separate disks, then I can speed up the comparison by reading both at the same time.

Hello

+4
source share
2 answers

This may require P / Invoke.

A way to find out if two partitions are on the same physical hard drive without WMI?

Top link:

The Win32 function you need is called DeviceIoControl (). API documentation can be found at http://msdn.microsoft.com/en-us/library/aa363216(VS.85).aspx . Call DeviceIoControl () with the control code IOCTL_STORAGE_GET_DEVICE_NUMBER, and you will get a physical disk for this partition descriptor. The device handle for the partition can be restored using the CreateFile () API.

+2
source

Read both at the same time.

In the worst case, this may be a little slower (depending on the actual physical disk (s)).

At best, it will be faster.

+3
source

Source: https://habr.com/ru/post/1342463/


All Articles